Пример #1
0
        private Statement GetStatementForOutput(int portIndex)
        {
            if (State == ElementState.Error)
            {
                return(null);
            }

            // Here the "portIndex" is back mapped to the corresponding "Statement"
            // object. However, not all "Statement" objects produce an output port,
            // so "portIndex" cannot be used directly to index into "codeStatements"
            // list. This loop goes through "codeStatements", decrementing "portIndex"
            // along the way to determine the right "Statement" object matching the
            // port index.
            //
            Statement statement = null;
            var       svs       = CodeBlockUtils.GetStatementVariables(codeStatements, true);

            for (int stmt = 0, port = 0; stmt < codeStatements.Count; stmt++)
            {
                if (CodeBlockUtils.DoesStatementRequireOutputPort(svs, stmt))
                {
                    if (port == portIndex)
                    {
                        statement = codeStatements[stmt];
                        break;
                    }

                    port = port + 1;
                }
            }

            return(statement);
        }
Пример #2
0
        /// <summary>
        /// For code block nodes, each output identifier of an output port is mapped.
        /// For an example, "p = 1" would have its internal identifier renamed to
        /// "pXXXX", where "XXXX" is the GUID of the code block node. This mapping is
        /// done to ensure the uniqueness of the output variable name.
        /// </summary>
        /// <param name="portIndex">Output port index</param>
        /// <param name="forRawName">Set this parameter to true to retrieve the
        /// original identifier name "p". If this parameter is false, the mapped
        /// identifer name "pXXXX" is returned instead.</param>
        /// <returns></returns>
        private IdentifierNode GetAstIdentifierForOutputIndexInternal(int portIndex, bool forRawName)
        {
            if (State == ElementState.Error)
            {
                return(null);
            }

            // Here the "portIndex" is back mapped to the corresponding "Statement"
            // object. However, not all "Statement" objects produce an output port,
            // so "portIndex" cannot be used directly to index into "codeStatements"
            // list. This loop goes through "codeStatements", decrementing "portIndex"
            // along the way to determine the right "Statement" object matching the
            // port index.
            //
            Statement statement = null;
            var       svs       = CodeBlockUtils.GetStatementVariables(codeStatements, true);

            for (int stmt = 0, port = 0; stmt < codeStatements.Count; stmt++)
            {
                if (CodeBlockUtils.DoesStatementRequireOutputPort(svs, stmt))
                {
                    if (port == portIndex)
                    {
                        statement = codeStatements[stmt];
                        break;
                    }

                    port = port + 1;
                }
            }

            if (statement == null)
            {
                return(null);
            }

            var binExprNode = statement.AstNode as BinaryExpressionNode;

            if (binExprNode == null || (binExprNode.LeftNode == null))
            {
                return(null);
            }

            var identNode   = binExprNode.LeftNode as IdentifierNode;
            var mappedIdent = NodeUtils.Clone(identNode);

            if (!forRawName)
            {
                MapIdentifiers(mappedIdent);
            }

            return(mappedIdent as IdentifierNode);
        }
Пример #3
0
        /// <summary>
        ///  Returns the corresponding output port index for a given defined variable
        /// </summary>
        /// <param name="variableName"></param>
        /// <returns></returns>
        public int GetOutportIndex(string variableName)
        {
            var svs = CodeBlockUtils.GetStatementVariables(codeStatements, true);

            for (int i = 0; i < codeStatements.Count; i++)
            {
                Statement s = codeStatements[i];
                if (CodeBlockUtils.DoesStatementRequireOutputPort(svs, i))
                {
                    List <string> varNames = Statement.GetDefinedVariableNames(s, true);
                    if (varNames.Contains(variableName))
                    {
                        return(i);
                    }
                }
            }
            return(-1);
        }