Example #1
0
 public Expression CompileBinOp(AstBinary bo)
 {
     return(bo.IsAssign
         ? CompileAssign(bo)
         : CompileBinOp(bo.Source, bo.Type,
                        CompileExpression(bo.Left),
                        CompileExpression(bo.Right)));
 }
Example #2
0
        AstBinary ProcessBinaryNode(AstBinary astBinary, bool inList)
        {
            var safeIsInRightSideOfBinary = _isInRightSideOfBinary;

            DescendNode(astBinary.Left);
            _isInRightSideOfBinary = true;
            DescendNode(astBinary.Right);
            _isInRightSideOfBinary = safeIsInRightSideOfBinary;
            return(astBinary);

            void DescendNode(AstNode node)
            {
                Stack.Add(node);
                Before(node, inList);
                Stack.Pop();
            }
        }
Example #3
0
            private Func <decimal, decimal, decimal> GetDecimalOp(AstBinary binary)
            {
                switch (binary.Name)
                {
                case "+":
                    return((a, b) => a + b);

                case "-":
                    return((a, b) => a - b);

                case "*":
                    return((a, b) => a * b);

                case "/":
                    return((a, b) => a / b);

                default:
                    throw new NotSupportedException(string.Format("Binary operator is not supported: {0}", binary.Name));
                }
            }
Example #4
0
 public object Visit(AstBinary binary)
 {
     return(GetDecimalOp(binary)(EvaluateDecimal(binary.Left), EvaluateDecimal(binary.Right)));
 }
Example #5
0
 public string Visit(AstBinary binary)
 {
     return(string.Format("({0} {1} {2})", binary.Left.Accept(this), binary.Name, binary.Right.Accept(this)));
 }
Example #6
0
 public Expression Visit(AstBinary binary)
 {
     return(Expression.MakeBinary(ResolveBinaryType(binary.Name), binary.Left.Accept(this),
                                  binary.Right.Accept(this)));
 }
Example #7
0
        Expression CompileAssign(AstBinary e)
        {
            var lval = ResolveExpression(e.Left, null);

            if (lval.IsInvalid)
            {
                return(Expression.Invalid);
            }

            var right = CompileExpression(e.Right);

            // Incremental assign-operators (+=, -= etc.)
            if (e.Type != AstBinaryType.Assign)
            {
                // Special case for +=, -= on events
                if (lval.ExpressionType == PartialExpressionType.Event)
                {
                    var p   = lval as PartialEvent;
                    var obj = p.Object;

                    if (obj != null)
                    {
                        Transforms.TryCreateReadonlyValueFieldIndirection(Namescope, ref obj);
                    }

                    switch (e.Type)
                    {
                    case AstBinaryType.AddAssign:
                        return(new AddListener(e.Source, obj, p.Event, CompileImplicitCast(e.Source, p.Event.ReturnType, right)));

                    case AstBinaryType.SubAssign:
                        return(new RemoveListener(e.Source, obj, p.Event, CompileImplicitCast(e.Source, p.Event.ReturnType, right)));
                    }
                }

                right = CompileBinOp(e.Source, e.RemoveAssign, CompilePartial(lval), right);
            }

            switch (lval.ExpressionType)
            {
            case PartialExpressionType.ArrayElement:
            {
                var p = lval as PartialArrayElement;
                return(new StoreElement(e.Source, p.Object, p.Index, CompileImplicitCast(right.Source, p.ElementType, right)));
            }

            case PartialExpressionType.Variable:
            {
                var p = lval as PartialVariable;
                return(new StoreLocal(e.Source, p.Variable, CompileImplicitCast(right.Source, p.Variable.ValueType, right)));
            }

            case PartialExpressionType.Parameter:
            {
                var p = lval as PartialParameter;

                return(new StoreArgument(e.Source, p.Function, p.Index, CompileImplicitCast(right.Source, p.Parameter.Type, right)));
            }

            case PartialExpressionType.Field:
            {
                var p = lval as PartialField;
                return(new StoreField(e.Source, VerifyLValue(p.Object) ? p.Object : Expression.Invalid, p.Field, CompileImplicitCast(right.Source, p.Field.ReturnType, right)));
            }

            case PartialExpressionType.Property:
            {
                var p = lval as PartialProperty;
                var s = CompileImplicitCast(right.Source, p.Property.ReturnType, right);
                return(p.Property.SetMethod == null
                        ? Error(lval.Source, ErrorCode.E2070, "The property " + p.Property.Quote() + " has no setter accessor")
                        : new SetProperty(e.Source, p.Object, p.Property, s));
            }

            case PartialExpressionType.Event:
            {
                var p = lval as PartialEvent;
                var s = CompileImplicitCast(right.Source, p.Event.ReturnType, right);
                return(p.Event.ImplicitField == null
                        ? Error(lval.Source, ErrorCode.E2071, "The event " + p.Event.Quote() + " has no implicit field and can only be used before '+=' or '-='")
                        : new StoreField(e.Source, p.Object, p.Event.ImplicitField, s));
            }

            case PartialExpressionType.Indexer:
            {
                var p = lval as PartialIndexer;
                var s = CompileImplicitCast(right.Source, p.Indexer.ReturnType, right);
                return(p.Indexer.SetMethod == null
                        ? Error(lval.Source, ErrorCode.E2026, "The indexer " + p.Indexer.Quote() + " has no setter accessor")
                        : new SetProperty(e.Source, p.Object, p.Indexer, s, p.Arguments));
            }

            case PartialExpressionType.This:
            {
                return(!IsFunctionScope
                        ? Error(lval.Source, ErrorCode.E0000, "'this' not allowed in current context")
                        : new StoreThis(e.Source, CompileImplicitCast(right.Source, Function.DeclaringType, right)));
            }
            }

            return(Error(e.Left.Source, ErrorCode.E2027, "Expression of type <" + lval.ExpressionType + "> cannot be used as left-hand side in an assignment"));
        }
Example #8
0
 public void WriteBinary(AstBinary a)
 {
     Write(a.Left);
     Write(a.Source);
     Write(a.Right);
 }
        public IEnumerable <AstNode> Visit(AstBinary binary)
        {
            yield return(binary.Left);

            yield return(binary.Right);
        }
 public virtual T Visit(AstBinary binary)
 {
     return(Default(binary));
 }