示例#1
0
        /// <summary>
        /// Generate code representing the specified value input.
        /// </summary>
        /// <param name="name">The name of the input.</param>
        /// <param name="outerOrder">The maximum binding strength (minimum order value) of any operators adjacent to "block".</param>
        public string ValueToCode(Block block, string name, int outerOrder)
        {
            if (outerOrder < 0)
            {
                throw new Exception(string.Format("Expecting valid order from block {0}", block.Type));
            }

            var targetBlock = block.GetInputTargetBlock(name);

            if (targetBlock == null)
            {
                return("");
            }

            var tuple = this.BlockToCode(targetBlock);

            if (tuple.IsEmpty)
            {
                return("");//disabled block
            }
            if (tuple.order < 0)
            {
                throw new Exception(string.Format("Expecting valid order from value block: {0}", targetBlock.Type));
            }

            bool parensNeeded = false;
            int  innerOrder   = tuple.order;

            if (outerOrder == innerOrder && (outerOrder == 0 || innerOrder == 99))
            {
                // Don't generate parens around NONE-NONE and ATOMIC-ATOMIC pairs.
                parensNeeded = false;
            }
            else if (outerOrder <= innerOrder)
            {
                // The operators outside this code are stronger than the operators
                // inside this code.  To prevent the code from being pulled apart,
                // wrap the code in parentheses.
                parensNeeded = true;
                //check for special exceptions
                if (mOrderExceptions != null && mOrderExceptions.Length > 0)
                {
                    for (int i = 0; i < mOrderExceptions.Length; i++)
                    {
                        if (mOrderExceptions[i].Key == outerOrder && mOrderExceptions[i].Value == innerOrder)
                        {
                            parensNeeded = false;
                            break;
                        }
                    }
                }
            }
            if (parensNeeded)
            {
                return("(" + tuple.code + ")");
            }
            return(tuple.code);
        }
        /// <summary>
        /// Run code representing the statement.
        /// </summary>
        public IEnumerator StatementRun(Block block, string name)
        {
            var targetBlock = block.GetInputTargetBlock(name);

            if (targetBlock == null)
            {
                Debug.Log(string.Format("Statement input block of {0} is null", block.Type));
                yield break;
            }
            if (targetBlock.PreviousConnection == null)
            {
                Debug.Log(string.Format("Statement input block of {0} must have a previous connection", block.Type));
                yield break;
            }

            yield return(RunBlock(targetBlock));
        }
        /// <summary>
        /// run code representing the specified value input.
        /// should return a DataStruct
        /// </summary>
        public CustomEnumerator ValueReturn(Block block, string name)
        {
            var targetBlock = block.GetInputTargetBlock(name);

            if (targetBlock == null)
            {
                Debug.Log(string.Format("Value input block of {0} is null", block.Type));
                return(new CustomEnumerator(null));
            }
            if (targetBlock.OutputConnection == null)
            {
                Debug.Log(string.Format("Value input block of {0} must have an output connection", block.Type));
                return(new CustomEnumerator(null));
            }

            CustomEnumerator etor = new CustomEnumerator(RunBlock(targetBlock));

            etor.Cmdtor = GetBlockInterpreter(targetBlock);
            return(etor);
        }
示例#4
0
        /// <summary>
        /// Generate code representing the statement. Indent the code.
        /// </summary>
        public string StatementToCode(Block block, string name)
        {
            var targetBlock = block.GetInputTargetBlock(name);

            if (targetBlock == null)
            {
                return("");
            }

            var tuple = this.BlockToCode(targetBlock);

            if (tuple.IsEmpty)
            {
                return("");//disabled block
            }
            if (tuple.order >= 0)
            {
                throw new Exception(string.Format("Expecting code from statement block: {0}", targetBlock.Type));
            }

            return(this.PrefixLines(tuple.code, Indent));
        }