示例#1
0
 /// <summary>
 /// Creates a matching for the specified kind of binary operation.
 /// </summary>
 /// <param name="kind">kind of binary operation to match</param>
 public static Expression.MatchFunction BinOp(BinOp.Kind kind)
 {
     return(Node(new BinOp()
     {
         Operation = kind
     }));
 }
示例#2
0
 /// <summary>
 /// Constructs a generator for binary expressions.
 /// </summary>
 /// <param name="kind">kind of binary expression to construct</param>
 /// <param name="g1">left operand generator</param>
 /// <param name="g2">right operand generator</param>
 public static ExpressionGenerator BinOp(BinOp.Kind kind,
                                         ExpressionGenerator g1, ExpressionGenerator g2)
 {
     return(() => new BinOp()
     {
         Operation = kind,
         Operand1 = g1(),
         Operand2 = g2()
     });
 }
示例#3
0
        /// <summary>
        /// Returns <c>true</c> if the expression is a binary operation.
        /// </summary>
        public static bool IsBinOp(this Expression e, BinOp.Kind op)
        {
            BinOp bop = e as BinOp;

            if (bop == null)
            {
                return(false);
            }
            return(bop.Operation == op);
        }
示例#4
0
        /// <summary>
        /// Creates a matching for the specified kind of binary operation.
        /// </summary>
        /// <param name="kind">kind of binary operation to match</param>
        /// <param name="peer">right child matching</param>
        public Matching MBinOp(BinOp.Kind kind, Matching peer)
        {
            BinOp cmp = new BinOp()
            {
                Operation = kind
            };
            Matching newm = new Matching();

            newm._func = e => e.NodeEquals(cmp) &&
                         this.Match(e.Children.ElementAt(0)) &&
                         peer.Match(e.Children.ElementAt(1));
            newm._gen = () => newm._expr == null ?
                        new BinOp()
            {
                Operation = kind, Operand1 = _gen(), Operand2 = peer._gen()
            } : newm._expr;
            return(newm);
        }
 /// <summary>
 /// Creates the attribute.
 /// </summary>
 /// <param name="kind">kind of binary operation</param>
 public MapToBinOp(BinOp.Kind kind)
 {
     Kind = kind;
 }