예제 #1
0
        /// <summary>
        /// Evaluates binary operation on all value combinations of the left and right operands.
        /// </summary>
        /// <param name="leftOperand">Entry with all possible left operands of binary operation.</param>
        /// <param name="binaryOperation">Binary operation to be performed.</param>
        /// <param name="rightOperand">Entry with all possible right operands of binary operation.</param>
        /// <returns>Resulting entry of performing the binary operation on all possible operands.</returns>
        public MemoryEntry Evaluate(MemoryEntry leftOperand, Operations binaryOperation,
                                    MemoryEntry rightOperand)
        {
            if (binaryOperation == Operations.Concat)
            {
                stringConverter.SetContext(flow);
                return(stringConverter.EvaluateConcatenation(leftOperand, rightOperand));
            }

            /* TODO: Replace logical operations in binary operation visitors with boolean converter
             * booleanConverter.SetContext(OutSet);
             * var booleanValue = booleanConverter.EvaluateLogicalOperation(leftOperand,
             *  binaryOperation, rightOperand);
             * if (booleanValue != null)
             * {
             *  return new MemoryEntry(booleanValue);
             * }
             */

            var values = new HashSet <Value>();

            foreach (var leftValue in leftOperand.PossibleValues)
            {
                // Gets visitor of left operand
                leftValue.Accept(this);
                Debug.Assert(visitor != null, "Visiting of left operand must return its visitor");

                visitor.SetContext(flow);
                var entry = visitor.Evaluate(binaryOperation, rightOperand);
                values.UnionWith(entry.PossibleValues);
            }

            postprocessValues(values);

            return(new MemoryEntry(values));
        }