Exemple #1
0
        public override void Visit(ConditionalOp op, Node n)
        {
            VisitScalarOpDefault(op, n);
            switch (op.OpType)
            {
            case OpType.And:
            case OpType.Or:
                AssertArity(n, 2);
                AssertBooleanOp(n.Child0.Op);
                AssertBooleanOp(n.Child1.Op);
                break;

            case OpType.Not:
                AssertArity(n, 1);
                AssertBooleanOp(n.Child0.Op);
                break;

            case OpType.IsNull:
                AssertArity(n, 1);
                break;

            default:
                AssertUnexpectedOp(op);
                break;
            }
            AssertBooleanOp(op);
        }
Exemple #2
0
        public void TestConditionalOpConstructor01()
        {
            ConditionalOp conditionalOp = new ConditionalOp();

            #region Record State
            ValueRecorder recorder = new ValueRecorder();
            recorder.Record((OperatorPriority)conditionalOp.Priority);
            recorder.FinishRecording();
            #endregion
        }
Exemple #3
0
        void ParseConditional()
        {
            Token token = this.PeekToken();

            this.CheckStartableToken(token);
            ConditionalOp co = new ConditionalOp();

            _tree.AddOperator(co);
            _tree.Push('?');
        }
 public virtual void WriteConditionalOp(ConditionalOp s, ExpressionUsage u)
 {
     Begin(u);
     WriteExpression(s.Condition, ExpressionUsage.Operand);
     Write(QuestionMark);
     WriteExpression(s.True, ExpressionUsage.Operand);
     Write(Colon);
     WriteExpression(s.False, ExpressionUsage.Operand);
     End(u);
 }
Exemple #5
0
        public void TestCreateConditionalOp01()
        {
            ConditionalOp conditionalOp = CreateConditionalOp01();

            Assert.IsNotNull(conditionalOp);
            #region Record State
            ValueRecorder recorder = new ValueRecorder();
            recorder.Record((OperatorPriority)conditionalOp.Priority);
            recorder.FinishRecording();
            #endregion
        }
Exemple #6
0
        public static Expression TransformNullOpToConditionalOp(this NullOp s, Essentials types, Namescope scope)
        {
            // a ?? b -> (temp = a, temp != null ? temp : b)
            //   OR   -> a != null ? a : b

            var left  = s.Left;
            var right = s.Right;
            var ind   = TryCreateIndirection(scope, ref left);

            var cond   = new ReferenceOp(s.Source, types.Bool, EqualityType.NotEqual, left, new Constant(s.Source, left.ReturnType, null));
            var result = new ConditionalOp(s.Source, cond, left, right);

            return(ind != null
                ? (Expression) new SequenceOp(ind, result)
                : result);
        }
Exemple #7
0
        public void TestEval01()
        {
            ConditionalOp conditionalOp = new ConditionalOp();

            Result[] arrResult = new Result[3];
            Result   res1      = new Result(true);
            Result   res2      = new Result(1);
            Result   res3      = new Result(0);

            arrResult[0] = res1;
            arrResult[1] = res2;
            arrResult[2] = res3;
            Evaluator evalutor = new Evaluator();
            //Test Procedure Call
            Result result = conditionalOp.Eval(evalutor, arrResult);

            //Post Condition Check
            Assert.AreEqual(1, result.Value);
        }
Exemple #8
0
		void ParseConditional() {
			Token token = this.PeekToken();
			this.CheckStartableToken(token);
			ConditionalOp co = new ConditionalOp();
			_tree.AddOperator(co);
			_tree.Push('?');
		}
        public override Node Visit(ConditionalOp op, Node n)
        {
            if (op.OpType
                != OpType.IsNull)
            {
                return VisitScalarOpDefault(op, n);
            }

            //
            // Special handling for IS NULL ops on structured types
            //
            // For structured types, we simply convert this into an AND chain of
            // IS NULL predicates, one for each property. There are a couple of
            // optimizations that we perform. 
            //
            // For entity types, we simply perfom the IS NULL operations on the 
            // key attributes alone. 
            //
            // Complex types must have a typeid property - the isnull is pushed to the
            // typeid property
            //
            // We do NOT support IsNull for Collections
            //

            var childOpType = (n.Child0.Op).Type;

            // Special cases are for structured types only 
            if (!TypeUtils.IsStructuredType(childOpType))
            {
                return VisitScalarOpDefault(op, n);
            }

            // visit the children first
            VisitChildren(n);

            var typeInfo = m_typeInfo.GetTypeInfo(childOpType);

            // Otherwise, build up an and-chain of is null checks for each appropriate
            // property - which should consist only of key properties for Entity types.
            List<md.EdmProperty> properties = null;
            List<Node> values = null;
            GetPropertyValues(typeInfo, OperationKind.IsNull, n.Child0, false, out properties, out values);

            PlanCompiler.Assert(
                properties.Count == values.Count && properties.Count > 0, "No properties returned from GetPropertyValues(IsNull)?");

            Node andNode = null;
            foreach (var propertyValue in values)
            {
                var isNullNode = m_command.CreateNode(m_command.CreateConditionalOp(OpType.IsNull), propertyValue);
                if (andNode == null)
                {
                    andNode = isNullNode;
                }
                else
                {
                    andNode = m_command.CreateNode(m_command.CreateConditionalOp(OpType.And), andNode, isNullNode);
                }
            }
            return andNode;
        }
 /// <summary>
 /// If it is a IsNull op over a row type or a complex type mark the type as needing a null sentinel.
 /// </summary>
 /// <param name="op"></param>
 /// <param name="n"></param>
 private void ProcessConditionalOp(ConditionalOp op, Node n)
 {
     if (op.OpType == OpType.IsNull && TypeSemantics.IsRowType(n.Child0.Op.Type)
         || TypeSemantics.IsComplexType(n.Child0.Op.Type))
     {
         StructuredTypeNullabilityAnalyzer.MarkAsNeedingNullSentinel(m_typesNeedingNullSentinel, n.Child0.Op.Type);
     }
 }
 /// <summary>
 /// Special processing for ConditionalOp is handled by <see cref="ProcessConditionalOp"/>
 /// </summary>
 /// <param name="op"></param>
 /// <param name="n"></param>
 /// <returns></returns>
 public override Node Visit(ConditionalOp op, Node n)
 {
     VisitScalarOpDefault(op, n);
     ProcessConditionalOp(op, n);
     return n;
 }
 public override void Visit(ConditionalOp op, Node n)
 {
     VisitScalarOpDefault(op, n);
     switch (op.OpType)
     {
         case OpType.And:
         case OpType.Or:
             AssertArity(n, 2);
             AssertBooleanOp(n.Child0.Op);
             AssertBooleanOp(n.Child1.Op);
             break;
         case OpType.Not:
             AssertArity(n, 1);
             AssertBooleanOp(n.Child0.Op);
             break;
         case OpType.IsNull:
             AssertArity(n, 1);
             break;
         default:
             AssertUnexpectedOp(op);
             break;
     }
     AssertBooleanOp(op);
 }
Exemple #13
0
 /// <summary>
 /// Copies a ConditionalOp
 /// </summary>
 /// <param name="op">The Op to Copy</param>
 /// <param name="n">The Node that references the Op</param>
 /// <returns>A copy of the original Node that references a copy of the original Op</returns>
 public override Node Visit(ConditionalOp op, Node n)
 {
     return(CopyDefault(m_destCmd.CreateConditionalOp(op.OpType), n));
 }
 /// <summary>
 ///     Visitor pattern method for ConditionalOp
 /// </summary>
 /// <param name="op"> The ConditionalOp being visited </param>
 /// <param name="n"> The Node that references the Op </param>
 public virtual void Visit(ConditionalOp op, Node n)
 {
     VisitScalarOpDefault(op, n);
 }
Exemple #15
0
 // <summary>
 // Copies a ConditionalOp
 // </summary>
 // <param name="op"> The Op to Copy </param>
 // <param name="n"> The Node that references the Op </param>
 // <returns> A copy of the original Node that references a copy of the original Op </returns>
 public override Node Visit(ConditionalOp op, Node n)
 {
     return CopyDefault(m_destCmd.CreateConditionalOp(op.OpType), n);
 }
Exemple #16
0
        internal static ConditionalOp CreateConditionalOp01()
        {
            ConditionalOp conditionalOp = new ConditionalOp();

            return(conditionalOp);
        }