Example #1
0
 private void WriteNestedExpression(BoundExpression node, OperatorPrecedence parentPrecedence)
 {
     if (node is BoundBinaryExpression binaryExpression)
     {
         WriteNestedExpression(
             binaryExpression,
             parentPrecedence,
             binaryExpression.Operator.SyntaxKind.GetBinaryOperatorPrecedence()
             ?? throw new Exception("Invalid operator")
             );
     }
     else
     {
         node.Accept(this);
     }
 }
Example #2
0
        /// <summary>
        /// Visits condition used to branch execution to true or false branch.
        /// </summary>
        /// <returns>Value indicating whether branch was used.</returns>
        /// <remarks>
        /// Because of minimal evaluation there is different FlowState for true and false branches,
        /// AND and OR operators have to take this into account.
        ///
        /// Also some other constructs may have side-effect for known branch,
        /// eg. <c>($x instanceof X)</c> implies ($x is X) in True branch.
        /// </remarks>
        internal bool VisitCondition(BoundExpression condition, ConditionBranch branch)
        {
            Contract.ThrowIfNull(condition);

            if (branch != ConditionBranch.AnyResult)
            {
                if (condition is BoundBinaryEx)
                {
                    Visit((BoundBinaryEx)condition, branch);
                    return(true);
                }
                if (condition is BoundUnaryEx unaryEx)
                {
                    Visit(unaryEx, branch);
                    return(true);
                }
                if (condition is BoundGlobalFunctionCall)
                {
                    VisitGlobalFunctionCall((BoundGlobalFunctionCall)condition, branch);
                    return(true);
                }
                if (condition is BoundInstanceOfEx)
                {
                    Visit((BoundInstanceOfEx)condition, branch);
                    return(true);
                }
                if (condition is BoundIsSetEx)
                {
                    Visit((BoundIsSetEx)condition, branch);
                    return(true);
                }
                //if (condition is EmptyEx)
                //{
                //    VisitEmptyEx((EmptyEx)condition, branch);
                //    return false;
                //}
            }

            // no effect
            condition.Accept(this);
            return(false);
        }
Example #3
0
        /// <summary>
        /// Visits condition used to branch execution to true or false branch.
        /// </summary>
        /// <remarks>
        /// Because of minimal evaluation there is different FlowState for true and false branches,
        /// AND and OR operators have to take this into account.
        ///
        /// Also some other constructs may have side-effect for known branch,
        /// eg. <c>($x instanceof X)</c> implies ($x is X) in True branch.
        /// </remarks>
        internal void VisitCondition(BoundExpression condition, ConditionBranch branch)
        {
            Contract.ThrowIfNull(condition);

            if (branch != ConditionBranch.AnyResult)
            {
                if (condition is BoundBinaryEx)
                {
                    Visit((BoundBinaryEx)condition, branch);
                    return;
                }
                if (condition is BoundUnaryEx)
                {
                    Visit((BoundUnaryEx)condition, branch);
                    return;
                }
                //if (condition is DirectFcnCall)
                //{
                //    VisitDirectFcnCall((DirectFcnCall)condition, branch);
                //    return;
                //}
                if (condition is BoundInstanceOfEx)
                {
                    Visit((BoundInstanceOfEx)condition, branch);
                    return;
                }
                //if (condition is IssetEx)
                //{
                //    VisitIssetEx((IssetEx)condition, branch);
                //    return;
                //}
                //if (condition is EmptyEx)
                //{
                //    VisitEmptyEx((EmptyEx)condition, branch);
                //    return;
                //}
            }

            // no effect
            condition.Accept(this);
        }
Example #4
0
    public static BoundConstant?Fold(BoundExpression expression)
    {
        var folding = new ConstantFolding();

        return(expression.Accept(folding));
    }