GetDefinedVariableNames() public static method

Returns the names of the variables that have been declared in the statement
public static GetDefinedVariableNames ( Statement s, bool onlyTopLevel ) : List
s Statement Statement whose variable names to be queried.
onlyTopLevel bool Bool to check if required to return reference variables in sub statements as well
return List
Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Call this method to get a list of lists of variables defined in
        /// the given set of Statement objects. This method is typically used
        /// in conjunction with DoesStatementRequireOutputPort method.
        /// </summary>
        /// <param name="statements">A list of Statement objects whose defined
        /// variables are to be retrieved. This list can be empty but it cannot
        /// be null.</param>
        /// <param name="onlyTopLevel">Set this parameter to false to retrieve
        /// all variables defined in nested Statement objects.</param>
        /// <returns>Returns a list of lists of variables defined by the given
        /// set of Statement objects.</returns>
        ///
        internal static IEnumerable <IEnumerable <string> > GetStatementVariables(
            IEnumerable <Statement> statements, bool onlyTopLevel)
        {
            if (statements == null)
            {
                throw new ArgumentNullException("statements");
            }

            var definedVariables = new List <List <string> >();

            foreach (var statement in statements)
            {
                definedVariables.Add(Statement.GetDefinedVariableNames(
                                         statement, onlyTopLevel));
            }

            return(definedVariables);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Returns the names of all the variables defined in this code block.
        /// </summary>
        /// <returns>List containing all the names</returns>
        public List <string> GetDefinedVariableNames()
        {
            var defVarNames = new List <string>();

            // For unbound identifier, ideally if there is an input connect
            // to it, it is defined variable. But here we have to be more
            // aggresive. For copy/paste, the connectors haven't been
            // created yet, so if a variable is defined in other CBN, even
            // that variable is defined in this CBN, it is not included in
            // the return value.
            defVarNames.AddRange(inputIdentifiers);

            // Then get all variabled on the LHS of the statements
            foreach (Statement stmnt in codeStatements)
            {
                defVarNames.AddRange(Statement.GetDefinedVariableNames(stmnt, true));
            }

            return(defVarNames);
        }