Ejemplo n.º 1
0
        public override void ExitCase2Expr(MiniSqlParserParser.Case2ExprContext context)
        {
            Expr elseResult  = null;
            var  results     = new List <Expr>();
            var  conditions  = new List <Predicate>();
            var  branchCount = context.K_WHEN().Length;
            var  comments    = this.GetComments(context);

            if (context.K_ELSE() != null)
            {
                elseResult = (Expr)_stack.Pop();
            }
            for (int i = 0; i < branchCount; ++i)
            {
                results.Insert(0, (Expr)_stack.Pop());
                conditions.Insert(0, (Predicate)_stack.Pop());
            }
            var node = new CaseExpr(conditions, results, elseResult, comments);

            _stack.Push(node);
        }
Ejemplo n.º 2
0
        public override void VisitAfter(CaseExpr expr)
        {
            if (expr.IsSimpleCase)
            {
                if (IsPlaceHolderExpr(expr.SearchExpr))
                {
                    expr.SearchExpr = Place((PlaceHolderExpr)expr.SearchExpr);
                }
                for (int i = 0; i < expr.Comparisons.Count; ++i)
                {
                    if (IsPlaceHolderExpr((Expr)expr.Comparisons[i]) ||
                        IsPlaceHolderExpr(expr.Results[i]))
                    {
                        expr.SetBranch(i
                                       , Place((PlaceHolderExpr)expr.Comparisons[i])
                                       , Place((PlaceHolderExpr)expr.Results[i]));
                    }
                }
            }
            else
            {
                for (int i = 0; i < expr.Conditions.Count; ++i)
                {
                    if (IsPlaceHolderPredicate((Predicate)expr.Conditions[i]) ||
                        IsPlaceHolderExpr(expr.Results[i]))
                    {
                        expr.SetBranch(i
                                       , Place((PlaceHolderPredicate)expr.Conditions[i])
                                       , Place((PlaceHolderExpr)expr.Results[i]));
                    }
                }
            }

            if (IsPlaceHolderExpr(expr.ElseResult))
            {
                expr.ElseResult = Place((PlaceHolderExpr)expr.ElseResult);
            }
        }
Ejemplo n.º 3
0
 virtual public void VisitOnElse(CaseExpr expr)
 {
 }
Ejemplo n.º 4
0
 virtual public void VisitOnThen(CaseExpr expr, int i)
 {
 }
Ejemplo n.º 5
0
 virtual public void VisitAfter(CaseExpr expr)
 {
 }
Ejemplo n.º 6
0
 virtual public void VisitBefore(CaseExpr expr)
 {
 }
        public override void VisitAfter(CaseExpr expr)
        {
            bool isReferenceEqual = true;

            Expr elseResult = null;

            if (expr.ElseResult != null)
            {
                elseResult       = (Expr)_stack.Pop();
                isReferenceEqual = isReferenceEqual && object.ReferenceEquals(expr.ElseResult, elseResult);
            }

            var results = new List <Expr>();

            for (var i = expr.Results.Count - 1; i >= 0; --i)
            {
                var result = (Expr)_stack.Pop();
                results.Insert(0, result);
                isReferenceEqual = isReferenceEqual && object.ReferenceEquals(expr.Results[i], result);
            }

            if (expr.IsSimpleCase)
            {
                var comparisons = new List <Expr>();
                for (var i = expr.Comparisons.Count - 1; i >= 0; --i)
                {
                    var comparison = (Expr)_stack.Pop();
                    comparisons.Insert(0, comparison);
                    isReferenceEqual = isReferenceEqual && object.ReferenceEquals(expr.Comparisons[i], comparison);
                }

                Expr searchExpr = (Expr)_stack.Pop();

                if (isReferenceEqual &&
                    object.ReferenceEquals(expr.SearchExpr, searchExpr))
                {
                    _stack.Push(expr);
                    return;
                }

                var node = new CaseExpr(searchExpr, comparisons, results, elseResult, expr.Comments.Clone());
                _stack.Push(node);
            }
            else
            {
                var conditions = new List <Predicate>();
                for (var i = expr.Conditions.Count - 1; i >= 0; --i)
                {
                    var condition = (Predicate)_stack.Pop();
                    conditions.Insert(0, condition);
                    isReferenceEqual = isReferenceEqual && object.ReferenceEquals(expr.Conditions[i], condition);
                }

                if (isReferenceEqual)
                {
                    _stack.Push(expr);
                    return;
                }

                var node = new CaseExpr(conditions, results, elseResult, expr.Comments.Clone());
                _stack.Push(node);
            }
        }
Ejemplo n.º 8
0
 public void VisitOnElse(CaseExpr expr)
 {
     _visitor.VisitOnElse(expr);
 }
Ejemplo n.º 9
0
 public void VisitOnThen(CaseExpr expr, int i)
 {
     _visitor.VisitOnThen(expr, i);
 }
Ejemplo n.º 10
0
 public void VisitAfter(CaseExpr expr)
 {
     _visitor.VisitAfter(expr);
 }
Ejemplo n.º 11
0
 public void VisitBefore(CaseExpr expr)
 {
     _visitor.VisitBefore(expr);
 }
Ejemplo n.º 12
0
 public sealed override void VisitAfter(CaseExpr expr)
 {
     --_caseNestLevel;
 }
Ejemplo n.º 13
0
 public sealed override void VisitBefore(CaseExpr expr)
 {
     ++_caseNestLevel;
 }