View over a Qil operator having three children.
Don't construct QIL nodes directly; instead, use the QilFactory.
상속: QilNode
예제 #1
0
        //-----------------------------------------------
        // choice
        //-----------------------------------------------
        public QilTernary Conditional(QilNode left, QilNode center, QilNode right)
        {
            QilTernary n = new QilTernary(QilNodeType.Conditional, left, center, right);

            n.XmlType = this.typeCheck.CheckConditional(n);
            TraceNode(n);
            return(n);
        }
예제 #2
0
 protected virtual QilNode VisitConditional(QilTernary n)
 {
     return(VisitChildren(n));
 }
예제 #3
0
 //-----------------------------------------------
 // choice
 //-----------------------------------------------
 public XmlQueryType CheckConditional(QilTernary node)
 {
     CheckXmlType(node.Left, XmlQueryTypeFactory.BooleanX);
     return(XmlQueryTypeFactory.Choice(node.Center.XmlType, node.Right.XmlType));
 }
예제 #4
0
 //-----------------------------------------------
 // choice
 //-----------------------------------------------
 public XmlQueryType CheckConditional(QilTernary node) {
     CheckXmlType(node.Left, XmlQueryTypeFactory.BooleanX);
     return XmlQueryTypeFactory.Choice(node.Center.XmlType, node.Right.XmlType);
 }
예제 #5
0
 protected virtual QilNode VisitConditional(QilTernary n) { return VisitChildren(n); }
예제 #6
0
 protected override QilNode VisitConditional(QilTernary n)
 {
     return(NoReplace(n));
 }
예제 #7
0
 protected override QilNode VisitConditional(QilTernary n) { return NoReplace(n); }
 protected override QilNode VisitConditional(QilTernary local0) {
     QilNode local1 = local0[0];
     QilNode local2 = local0[1];
     QilNode local3 = local0[2];
     if (this[XmlILOptimization.FoldNone]) {
         if ( (object) ( (local1).XmlType ) == (object) XmlQueryTypeFactory.None ) {
             if (AllowReplace(XmlILOptimization.FoldNone, local0)) {
                 return Replace(XmlILOptimization.FoldNone, local0, VisitNop(f.Nop(local1)));
             }
         }
     }
     if (this[XmlILOptimization.EliminateConditional]) {
         if (local1.NodeType == QilNodeType.True) {
             if (AllowReplace(XmlILOptimization.EliminateConditional, local0)) {
                 return Replace(XmlILOptimization.EliminateConditional, local0, local2);
             }
         }
     }
     if (this[XmlILOptimization.EliminateConditional]) {
         if (local1.NodeType == QilNodeType.False) {
             if (AllowReplace(XmlILOptimization.EliminateConditional, local0)) {
                 return Replace(XmlILOptimization.EliminateConditional, local0, local3);
             }
         }
     }
     if (this[XmlILOptimization.EliminateConditional]) {
         if (local2.NodeType == QilNodeType.True) {
             if (local3.NodeType == QilNodeType.False) {
                 if (AllowReplace(XmlILOptimization.EliminateConditional, local0)) {
                     return Replace(XmlILOptimization.EliminateConditional, local0, local1);
                 }
             }
         }
     }
     if (this[XmlILOptimization.EliminateConditional]) {
         if (local2.NodeType == QilNodeType.False) {
             if (local3.NodeType == QilNodeType.True) {
                 if (AllowReplace(XmlILOptimization.EliminateConditional, local0)) {
                     return Replace(XmlILOptimization.EliminateConditional, local0, VisitNot(f.Not(local1)));
                 }
             }
         }
     }
     if (this[XmlILOptimization.FoldConditionalNot]) {
         if (local1.NodeType == QilNodeType.Not) {
             QilNode local4 = local1[0];
             if (AllowReplace(XmlILOptimization.FoldConditionalNot, local0)) {
                 return Replace(XmlILOptimization.FoldConditionalNot, local0, VisitConditional(f.Conditional(local4, local3, local2)));
             }
         }
     }
     if (this[XmlILOptimization.NormalizeConditionalText]) {
         if (local2.NodeType == QilNodeType.TextCtor) {
             QilNode local4 = local2[0];
             if (local3.NodeType == QilNodeType.TextCtor) {
                 QilNode local5 = local3[0];
                 if (AllowReplace(XmlILOptimization.NormalizeConditionalText, local0)) {
                     return Replace(XmlILOptimization.NormalizeConditionalText, local0, VisitTextCtor(f.TextCtor(VisitConditional(f.Conditional(local1, local4, local5)))));
                 }
             }
         }
     }
     return NoReplace(local0);
 }
예제 #9
0
 //-----------------------------------------------
 // choice
 //-----------------------------------------------
 public QilTernary Conditional(QilNode left, QilNode center, QilNode right) {
     QilTernary n = new QilTernary(QilNodeType.Conditional, left, center, right);
     n.XmlType = this.typeCheck.CheckConditional(n);
     TraceNode(n);
     return n;
 }
예제 #10
0
        /// <summary>
        /// Analyze conditional.
        /// </summary>
        protected virtual void AnalyzeConditional(QilTernary ndCond, XmlILConstructInfo info) {
            PossibleXmlStates xstatesTrue;

            // Ensure that construct method is Writer
            info.ConstructMethod = XmlILConstructMethod.Writer;

            // Visit true branch; save resulting states
            ndCond.Center = AnalyzeContent(ndCond.Center);
            xstatesTrue = this.xstates;

            // Restore starting states and visit false branch
            this.xstates = info.InitialStates;
            ndCond.Right = AnalyzeContent(ndCond.Right);

            // Conditional ending states consist of combination of true and false branch states
            if (xstatesTrue != this.xstates)
                this.xstates = PossibleXmlStates.Any;
        }
예제 #11
0
        /// <summary>
        /// Generate code for QilNodeType.Conditional.
        /// </summary>
        protected override QilNode VisitConditional(QilTernary ndCond)
        {
            XmlILConstructInfo info = XmlILConstructInfo.Read(ndCond);

            if (info.ConstructMethod == XmlILConstructMethod.Writer)
            {
                Label lblFalse, lblDone;

                // Evaluate if test
                lblFalse = _helper.DefineLabel();
                NestedVisitWithBranch(ndCond.Left, BranchingContext.OnFalse, lblFalse);

                // Generate true branch code
                NestedVisit(ndCond.Center);

                // Generate false branch code.  If false branch is the empty list,
                if (ndCond.Right.NodeType == QilNodeType.Sequence && ndCond.Right.Count == 0)
                {
                    // Then generate simplified code that doesn't contain a false branch
                    _helper.MarkLabel(lblFalse);
                    NestedVisit(ndCond.Right);
                }
                else
                {
                    // Jump past false branch
                    lblDone = _helper.DefineLabel();
                    _helper.EmitUnconditionalBranch(OpCodes.Br, lblDone);

                    // Generate false branch code
                    _helper.MarkLabel(lblFalse);
                    NestedVisit(ndCond.Right);

                    _helper.MarkLabel(lblDone);
                }

                _iterCurr.Storage = StorageDescriptor.None();
            }
            else
            {
                IteratorDescriptor iterInfoTrue;
                LocalBuilder locBool = null, locCond = null;
                Label lblFalse, lblDone, lblNext;
                Type itemStorageType = GetItemStorageType(ndCond);
                Debug.Assert(info.ConstructMethod == XmlILConstructMethod.Iterator);

                // Evaluate conditional test -- save boolean result in boolResult
                Debug.Assert(ndCond.Left.XmlType.TypeCode == XmlTypeCode.Boolean);
                lblFalse = _helper.DefineLabel();

                if (ndCond.XmlType.IsSingleton)
                {
                    // if (!bool-expr) goto LabelFalse;
                    NestedVisitWithBranch(ndCond.Left, BranchingContext.OnFalse, lblFalse);
                }
                else
                {
                    // CondType itemCond;
                    // int boolResult = bool-expr;
                    locCond = _helper.DeclareLocal("$$$cond", itemStorageType);
                    locBool = _helper.DeclareLocal("$$$boolResult", typeof(bool));
                    NestedVisitEnsureLocal(ndCond.Left, locBool);

                    // if (!boolResult) goto LabelFalse;
                    _helper.Emit(OpCodes.Ldloc, locBool);
                    _helper.Emit(OpCodes.Brfalse, lblFalse);
                }

                // Generate code for true branch
                ConditionalBranch(ndCond.Center, itemStorageType, locCond);
                iterInfoTrue = _iterNested;

                // goto LabelDone;
                lblDone = _helper.DefineLabel();
                _helper.EmitUnconditionalBranch(OpCodes.Br, lblDone);

                // Generate code for false branch
                // LabelFalse:
                _helper.MarkLabel(lblFalse);
                ConditionalBranch(ndCond.Right, itemStorageType, locCond);

                // If conditional is not cardinality one, then need to iterate through all values
                if (!ndCond.XmlType.IsSingleton)
                {
                    Debug.Assert(!ndCond.Center.XmlType.IsSingleton || !ndCond.Right.XmlType.IsSingleton);

                    // IL's rules do not allow OpCodes.Br here
                    // goto LabelDone;
                    _helper.EmitUnconditionalBranch(OpCodes.Brtrue, lblDone);

                    // LabelNext:
                    lblNext = _helper.DefineLabel();
                    _helper.MarkLabel(lblNext);

                    // if (boolResult) goto LabelNextTrue else goto LabelNextFalse;
                    _helper.Emit(OpCodes.Ldloc, locBool);
                    _helper.Emit(OpCodes.Brtrue, iterInfoTrue.GetLabelNext());
                    _helper.EmitUnconditionalBranch(OpCodes.Br, _iterNested.GetLabelNext());

                    _iterCurr.SetIterator(lblNext, StorageDescriptor.Local(locCond, itemStorageType, false));
                }

                // LabelDone:
                _helper.MarkLabel(lblDone);
            }

            return ndCond;
        }
예제 #12
0
 protected override QilNode VisitConditional(QilTernary local0)
 {
     QilNode local1 = local0[0];
     QilNode local2 = local0[1];
     QilNode local3 = local0[2];
     if (this[XmlILOptimization.FoldNone])
     {
         if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None)
         {
             // PATTERN: [FoldNone] (Conditional $x:* ^ (None? (TypeOf $x)) * *) => (Nop $x)
             if (AllowReplace(XmlILOptimization.FoldNone, local0))
             {
                 return Replace(XmlILOptimization.FoldNone, local0, VisitNop(f.Nop(local1)));
             }
         }
     }
     if (this[XmlILOptimization.EliminateConditional])
     {
         if (local1.NodeType == QilNodeType.True)
         {
             // PATTERN: [EliminateConditional] (Conditional (True) $x:* *) => $x
             if (AllowReplace(XmlILOptimization.EliminateConditional, local0))
             {
                 return Replace(XmlILOptimization.EliminateConditional, local0, local2);
             }
         }
     }
     if (this[XmlILOptimization.EliminateConditional])
     {
         if (local1.NodeType == QilNodeType.False)
         {
             // PATTERN: [EliminateConditional] (Conditional (False) * $x:*) => $x
             if (AllowReplace(XmlILOptimization.EliminateConditional, local0))
             {
                 return Replace(XmlILOptimization.EliminateConditional, local0, local3);
             }
         }
     }
     if (this[XmlILOptimization.EliminateConditional])
     {
         if (local2.NodeType == QilNodeType.True)
         {
             if (local3.NodeType == QilNodeType.False)
             {
                 // PATTERN: [EliminateConditional] (Conditional $x:* (True) (False)) => $x
                 if (AllowReplace(XmlILOptimization.EliminateConditional, local0))
                 {
                     return Replace(XmlILOptimization.EliminateConditional, local0, local1);
                 }
             }
         }
     }
     if (this[XmlILOptimization.EliminateConditional])
     {
         if (local2.NodeType == QilNodeType.False)
         {
             if (local3.NodeType == QilNodeType.True)
             {
                 // PATTERN: [EliminateConditional] (Conditional $x:* (False) (True)) => (Not $x)
                 if (AllowReplace(XmlILOptimization.EliminateConditional, local0))
                 {
                     return Replace(XmlILOptimization.EliminateConditional, local0, VisitNot(f.Not(local1)));
                 }
             }
         }
     }
     if (this[XmlILOptimization.FoldConditionalNot])
     {
         if (local1.NodeType == QilNodeType.Not)
         {
             QilNode local4 = local1[0];
             // PATTERN: [FoldConditionalNot] (Conditional (Not $x:*) $t:* $f:*) => (Conditional $x $f $t)
             if (AllowReplace(XmlILOptimization.FoldConditionalNot, local0))
             {
                 return Replace(XmlILOptimization.FoldConditionalNot, local0, VisitConditional(f.Conditional(local4, local3, local2)));
             }
         }
     }
     if (this[XmlILOptimization.NormalizeConditionalText])
     {
         if (local2.NodeType == QilNodeType.TextCtor)
         {
             QilNode local4 = local2[0];
             if (local3.NodeType == QilNodeType.TextCtor)
             {
                 QilNode local5 = local3[0];
                 // PATTERN: [NormalizeConditionalText] (Conditional $cond:* $left:(TextCtor $leftText:*) $right:(TextCtor $rightText:*)) => (TextCtor (Conditional $cond $leftText $rightText))
                 if (AllowReplace(XmlILOptimization.NormalizeConditionalText, local0))
                 {
                     return Replace(XmlILOptimization.NormalizeConditionalText, local0, VisitTextCtor(f.TextCtor(VisitConditional(f.Conditional(local1, local4, local5)))));
                 }
             }
         }
     }
     return NoReplace(local0);
 }