コード例 #1
0
        internal override void CollectSequenceExpressions(List <StatementSyntax> expressions)
        {
            // Collect mine input expressions and pushed expressions
            CollectInputExpressions(expressions);

            var trueStatments  = new List <StatementSyntax>();
            var falseStatments = new List <StatementSyntax>();

            // Sequence outputs can be connected only to one input
            if (m_nextTrueSequenceNode != null)
            {
                m_nextTrueSequenceNode.CollectSequenceExpressions(trueStatments);
            }

            if (m_nextFalseSequenceNode != null)
            {
                m_nextFalseSequenceNode.CollectSequenceExpressions(falseStatments);
            }

            var inputNodeVariableName = m_comparerNode.VariableSyntaxName(ObjectBuilder.InputID.VariableName);

            // write my expression before the collected inputs
            expressions.Add(MySyntaxFactory.IfExpressionSyntax(inputNodeVariableName, trueStatments, falseStatments));
        }
コード例 #2
0
        internal override void CollectSequenceExpressions(List <StatementSyntax> expressions)
        {
            base.CollectInputExpressions(expressions);

            // We can ignore the nodes with empty bodies
            if (m_bodySequence != null)
            {
                var bodySyntax = new List <StatementSyntax>();
                // Collect body expressions
                m_bodySequence.CollectSequenceExpressions(bodySyntax);

                // Create syntax for first index of for loop
                ExpressionSyntax firstIndexExpression;
                if (m_firstInput != null)
                {
                    firstIndexExpression = SyntaxFactory.IdentifierName(
                        m_firstInput.VariableSyntaxName(ObjectBuilder.FirstIndexValueInput.VariableName)
                        );
                }
                else
                {
                    firstIndexExpression = MySyntaxFactory.Literal(
                        typeof(int).Signature(),
                        ObjectBuilder.FirstIndexValue
                        );
                }

                // Create syntax for last index condition
                ExpressionSyntax lastIndexExpression;
                if (m_lastInput != null)
                {
                    lastIndexExpression = SyntaxFactory.IdentifierName(
                        m_lastInput.VariableSyntaxName(ObjectBuilder.LastIndexValueInput.VariableName)
                        );
                }
                else
                {
                    lastIndexExpression = MySyntaxFactory.Literal(typeof(int).Signature(), ObjectBuilder.LastIndexValue);
                }

                // Create syntax for increment
                ExpressionSyntax incrementExpression;
                if (m_incrementInput != null)
                {
                    incrementExpression = SyntaxFactory.IdentifierName(
                        m_incrementInput.VariableSyntaxName(ObjectBuilder.IncrementValueInput.VariableName)
                        );
                }
                else
                {
                    incrementExpression = MySyntaxFactory.Literal(typeof(int).Signature(), ObjectBuilder.IncrementValue);
                }

                // Put the for statement syntax together
                var forStatement = SyntaxFactory.ForStatement(
                    SyntaxFactory.Block(bodySyntax)
                    ).WithDeclaration(
                    SyntaxFactory.VariableDeclaration(
                        SyntaxFactory.PredefinedType(
                            SyntaxFactory.Token(SyntaxKind.IntKeyword)))
                    .WithVariables(
                        SyntaxFactory.SingletonSeparatedList <VariableDeclaratorSyntax>(
                            SyntaxFactory.VariableDeclarator(
                                SyntaxFactory.Identifier(VariableSyntaxName()))
                            .WithInitializer(
                                SyntaxFactory.EqualsValueClause(
                                    firstIndexExpression
                                    )
                                )
                            )
                        )
                    ).WithCondition(
                    SyntaxFactory.BinaryExpression(
                        SyntaxKind.LessThanOrEqualExpression,
                        SyntaxFactory.IdentifierName(VariableSyntaxName()),
                        lastIndexExpression
                        )
                    ).WithIncrementors(
                    SyntaxFactory.SingletonSeparatedList <ExpressionSyntax>(
                        SyntaxFactory.AssignmentExpression(
                            SyntaxKind.AddAssignmentExpression,
                            SyntaxFactory.IdentifierName(VariableSyntaxName()),
                            incrementExpression
                            )
                        )
                    );

                expressions.Add(forStatement);
            }

            // Ignore if not present
            if (m_finishSequence != null)
            {
                m_finishSequence.CollectSequenceExpressions(expressions);
            }
        }
コード例 #3
0
        internal override void CollectSequenceExpressions(List <StatementSyntax> expressions)
        {
            // Collect input only from these nodes that are inputs for this node.
            m_toCollectNodeCache.Clear();
            foreach (var subTreeNode in SubTreeNodes)
            {
                var directConnection = false;
                foreach (var outputNode in subTreeNode.Outputs)
                {
                    // Must be an input
                    if (outputNode == this && !outputNode.Collected)
                    {
                        directConnection = true;
                        break;
                    }
                }

                if (directConnection)
                {
                    subTreeNode.CollectInputExpressions(expressions);
                }
                else
                {
                    // Cache these that are getting the input from this one.
                    m_toCollectNodeCache.Add(subTreeNode);
                }
            }

            // We can ignore the nodes with empty bodies
            if (m_bodySequence != null)
            {
                var bodySyntax = new List <StatementSyntax>();

                // Collect the assigned bodies from
                foreach (var node in m_toCollectNodeCache)
                {
                    node.CollectInputExpressions(bodySyntax);
                }

                // Collect body expressions
                m_bodySequence.CollectSequenceExpressions(bodySyntax);

                // Create syntax for first index of for loop
                ExpressionSyntax firstIndexExpression;
                if (m_firstInput != null)
                {
                    firstIndexExpression = SyntaxFactory.IdentifierName(
                        m_firstInput.VariableSyntaxName(ObjectBuilder.FirstIndexValueInput.VariableName)
                        );
                }
                else
                {
                    firstIndexExpression = MySyntaxFactory.Literal(
                        typeof(int).Signature(),
                        ObjectBuilder.FirstIndexValue
                        );
                }

                // Create syntax for last index condition
                ExpressionSyntax lastIndexExpression;
                if (m_lastInput != null)
                {
                    lastIndexExpression = SyntaxFactory.IdentifierName(
                        m_lastInput.VariableSyntaxName(ObjectBuilder.LastIndexValueInput.VariableName)
                        );
                }
                else
                {
                    lastIndexExpression = MySyntaxFactory.Literal(typeof(int).Signature(), ObjectBuilder.LastIndexValue);
                }

                // Create syntax for increment
                ExpressionSyntax incrementExpression;
                if (m_incrementInput != null)
                {
                    incrementExpression = SyntaxFactory.IdentifierName(
                        m_incrementInput.VariableSyntaxName(ObjectBuilder.IncrementValueInput.VariableName)
                        );
                }
                else
                {
                    incrementExpression = MySyntaxFactory.Literal(typeof(int).Signature(), ObjectBuilder.IncrementValue);
                }

                // Put the for statement syntax together
                var forStatement = SyntaxFactory.ForStatement(
                    SyntaxFactory.Block(bodySyntax)
                    ).WithDeclaration(
                    SyntaxFactory.VariableDeclaration(
                        SyntaxFactory.PredefinedType(
                            SyntaxFactory.Token(SyntaxKind.IntKeyword)))
                    .WithVariables(
                        SyntaxFactory.SingletonSeparatedList <VariableDeclaratorSyntax>(
                            SyntaxFactory.VariableDeclarator(
                                SyntaxFactory.Identifier(VariableSyntaxName()))
                            .WithInitializer(
                                SyntaxFactory.EqualsValueClause(
                                    firstIndexExpression
                                    )
                                )
                            )
                        )
                    ).WithCondition(
                    SyntaxFactory.BinaryExpression(
                        SyntaxKind.LessThanOrEqualExpression,
                        SyntaxFactory.IdentifierName(VariableSyntaxName()),
                        lastIndexExpression
                        )
                    ).WithIncrementors(
                    SyntaxFactory.SingletonSeparatedList <ExpressionSyntax>(
                        SyntaxFactory.AssignmentExpression(
                            SyntaxKind.AddAssignmentExpression,
                            SyntaxFactory.IdentifierName(VariableSyntaxName()),
                            incrementExpression
                            )
                        )
                    );

                expressions.Add(forStatement);
            }

            // Ignore if not present
            if (m_finishSequence != null)
            {
                m_finishSequence.CollectSequenceExpressions(expressions);
            }
        }