Example #1
0
        /// <summary>
        /// Find all user-created procedure definitions in a workspace.
        /// </summary>
        /// <param name="root">Root workspace.</param>
        /// <returns>Pair of arrays, the first contains procedures without return variables, the
        /// second with. Each procedure is defined by a three-element list of name, parameter
        /// list, and return value boolean.</returns>
        public static Tuple <string, string[], bool>[][] allProcedures(Workspace root)
        {
            var blocks             = root.getAllBlocks();
            var proceduresReturn   = new JsArray <Tuple <string, string[], bool> >();
            var proceduresNoReturn = new JsArray <Tuple <string, string[], bool> >();

            for (var i = 0; i < blocks.Length; i++)
            {
                var block = blocks[i];
                if ((block.type == ProceduresDefnoreturnBlock.type_name) ||
                    (block.type == ProceduresDefreturnBlock.type_name))
                {
                    var tuple = ((ProceduresDefBlock)block).getProcedureDef();
                    if (tuple != null)
                    {
                        if (tuple.Item3)
                        {
                            proceduresReturn.Push(tuple);
                        }
                        else
                        {
                            proceduresNoReturn.Push(tuple);
                        }
                    }
                }
            }
            proceduresNoReturn.Sort(procTupleComparator_);
            proceduresReturn.Sort(procTupleComparator_);
            return(new Tuple <string, string[], bool>[][] { proceduresNoReturn, proceduresReturn });
        }
Example #2
0
        /// <summary>
        /// Find all the callers of a named procedure.
        /// </summary>
        /// <param name="name">Name of procedure.</param>
        /// <param name="workspace">The workspace to find callers in.</param>
        /// <returns>Array of caller blocks.</returns>
        public ProceduresCallBlock[] getCallers(string name, Workspace workspace)
        {
            var callers = new JsArray <ProceduresCallBlock>();
            var blocks  = workspace.getAllBlocks();

            // Iterate through every block and check the name.
            for (var i = 0; i < blocks.Length; i++)
            {
                var block = blocks[i];
                if ((block.type == ProceduresCallnoreturnBlock.type_name) ||
                    (block.type == ProceduresCallreturnBlock.type_name))
                {
                    var procName = ((ProceduresCallBlock)block).getProcedureCall();
                    // Procedure name may be null if the block is only half-built.
                    if (procName != null && Core.Names.equals(procName, name))
                    {
                        callers.Push((ProceduresCallBlock)block);
                    }
                }
            }
            return(callers);
        }
Example #3
0
        /// <summary>
        /// Does this procedure have a legal name?  Illegal names include names of
        /// procedures already defined.
        /// </summary>
        /// <param name="name">The questionable name.</param>
        /// <param name="workspace">The workspace to scan for collisions.</param>
        /// <param name="opt_exclude">Optional block to exclude from
        /// comparisons (one doesn't want to collide with oneself).</param>
        /// <returns>True if the name is legal.</returns>
        public static bool isLegalName_(string name, Workspace workspace, Block opt_exclude = null)
        {
            var blocks = workspace.getAllBlocks();

            // Iterate through every block and check the name.
            for (var i = 0; i < blocks.Length; i++)
            {
                if (blocks[i] == opt_exclude)
                {
                    continue;
                }
                var block = blocks[i];
                if ((block.type == ProceduresDefnoreturnBlock.type_name) ||
                    (block.type == ProceduresDefreturnBlock.type_name))
                {
                    var procName = ((ProceduresDefBlock)block).getProcedureDef();
                    if (Core.Names.equals(procName.Item1, name))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }