public NodeBinOp(BinOp type, AstNode left, AstNode right) : base("Binary Operation", NodeType.Operation) { Type = type; AddChild (left); AddChild (right); }
static Node ParseExpression() { Node res = ParseTerm(); Node N2 = null; while (tokens.CurrentIsExpr()) { if (tokens.Current.Type == TokenTypes.PLUS) { tokens.SelectNext(); N2 = ParseTerm(); res = new BinOp('+', res, N2); } else if (tokens.Current.Type == TokenTypes.MINUS) { tokens.SelectNext(); N2 = ParseTerm(); res = new BinOp('-', res, N2); } else if (tokens.Current.Type == TokenTypes.KEYWORD) { if (tokens.Current.Value != Keywords.OR) { throw new RaulException($"Unexpected KEYWORD at pos {tokens.Position}"); } tokens.SelectNext(); N2 = ParseFactor(); res = new BinOp("OR", res, N2); } } return(res); }
static void Check(object x, object y, BinOp op, bool ovf) { string exp = string.Format("{0} {1} {2}", x, ToString(op), y); Console.WriteLine("Overflow is {0}expected in ({1})!!!", ovf ? "" : "un", exp); try { checked { Console.WriteLine(Op(x, y, op)); if (ovf) { Console.WriteLine("error PFC0001: no expected overflow for ({0})", exp); } else { Console.WriteLine("ok"); } } } catch (OverflowException) { if (ovf) { Console.WriteLine("ok"); } else { Console.WriteLine("error PFC0002: unexpected overflow for ({0})", exp); } } }
static Node ParseTerm() { Node res = ParseFactor(); Node N2 = null; while (tokens.CurrentIsTerm()) { if (tokens.Current.Type == TokenTypes.STAR) { tokens.SelectNext(); N2 = ParseFactor(); res = new BinOp('*', res, N2); } else if (tokens.Current.Type == TokenTypes.SLASH) { tokens.SelectNext(); N2 = ParseFactor(); res = new BinOp('/', res, N2); } else if (tokens.Current.Type == TokenTypes.KEYWORD) { if (tokens.Current.Value != Keywords.AND) { throw new RaulException($"Unexpected KEYWORD at pos {tokens.Position}"); } tokens.SelectNext(); N2 = ParseFactor(); res = new BinOp("AND", res, N2); } } return(res); }
/// <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; }
public Binary(ParseTree.Node?parseTreeNode, Expression left, BinOp op, Expression right) : base(parseTreeNode) { Left = left; Operator = op; Right = right; }
private static void binop(SparseBitSet a, SparseBitSet b, BinOp op) { int nsize = a._size + b._size; long[] nbits; int [] noffs; int a_zero, a_size; // be very clever and avoid allocating more memory if we can. if (a.bits.Length < nsize) { // oh well, have to make working space. nbits = new long[nsize]; noffs = new int [nsize]; a_zero = 0; a_size = a._size; } else { // reduce, reuse, recycle! nbits = a.bits; noffs = a.offs; a_zero = a.bits.Length - a._size; a_size = a.bits.Length; // System.arraycopy(a.bits, 0, a.bits, a_zero, a.size); Array.Copy(a.bits, 0, a.bits, a_zero, a._size); //System.arraycopy(a.offs, 0, a.offs, a_zero, a.size); Array.Copy(a.offs, 0, a.offs, a_zero, a._size); } // ok, crunch through and binop those sets! nsize = 0; for (int i = a_zero, j = 0; i < a_size || j < b._size;) { long nb; int no; if (i < a_size && (j >= b._size || a.offs[i] < b.offs[j])) { nb = op.op(a.bits[i], 0); no = a.offs[i]; i++; } else if (j < b._size && (i >= a_size || a.offs[i] > b.offs[j])) { nb = op.op(0, b.bits[j]); no = b.offs[j]; j++; } else { // equal keys; merge. nb = op.op(a.bits[i], b.bits[j]); no = a.offs[i]; i++; j++; } if (nb != 0) { nbits[nsize] = nb; noffs[nsize] = no; nsize++; } } a.bits = nbits; a.offs = noffs; a._size = nsize; }
static T[] Zip<T>(T[] a, T[] b, BinOp<T> op) { T[] array = new T[a.Length]; for (int i = 0; i < a.Length; i++) { T result = op(a[i], b[i]); array[i] = result; } return array; }
/// <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); }
void binop(BitSet a, BitSet b, BinOp op) { int n_sum = a.inuse + b.inuse; ulong[] n_bits = new ulong[n_sum]; int[] n_offs = new int [n_sum]; int n_len = 0; int a_len = a.bits.Length; int b_len = b.bits.Length; for (int i = 0, j = 0; i < a_len || j < b_len;) { ulong nb; int no; if (i < a_len && ((j >= b_len) || (a.offs[i] < b.offs[j]))) { nb = op(a.bits[i], 0); // invoke delegate no = a.offs[i]; i++; } else if (j < b_len && ((i >= a_len) || (a.offs[i] > b.offs[j]))) { nb = op(0, b.bits[j]); // invoke delegate no = b.offs[j]; j++; } else { // equal keys; merge. nb = op(a.bits[i], b.bits[j]); // invoke delegate no = a.offs[i]; i++; j++; } if (nb != 0) { n_bits[n_len] = nb; n_offs[n_len] = no; n_len++; } } if (n_len > 0) { a.bits = new ulong[n_len]; a.offs = new int[n_len]; a.inuse = n_len; System.Array.Copy(n_bits, 0, a.bits, 0, n_len); System.Array.Copy(n_offs, 0, a.offs, 0, n_len); } else { bits = new ulong[4]; offs = new int [4]; a.inuse = 0; } }
public Expression TransformBinOp(BinOp x) { Expression dx0 = der(x.Operand1); Expression dx1 = der(x.Operand2); switch (x.Operation) { case BinOp.Kind.Add: return(dx0 + dx1); case BinOp.Kind.And: case BinOp.Kind.Concat: throw new NotImplementedException(); case BinOp.Kind.Div: return((dx0 * x.Operand2 - x.Operand1 * dx1) / (x.Operand2 * x.Operand2)); case BinOp.Kind.Eq: throw new NotImplementedException(); case BinOp.Kind.Exp: return(x * (dx1 * Expression.Log(x.Operand1) + dx0 * x.Operand2 / x.Operand1)); case BinOp.Kind.Gt: case BinOp.Kind.GtEq: throw new NotImplementedException(); case BinOp.Kind.Log: throw new NotImplementedException(); case BinOp.Kind.LShift: case BinOp.Kind.Lt: case BinOp.Kind.LtEq: throw new NotImplementedException(); case BinOp.Kind.Mul: return(dx0 * x.Operand2 + dx1 * x.Operand1); case BinOp.Kind.NEq: case BinOp.Kind.Or: case BinOp.Kind.Rem: case BinOp.Kind.RShift: throw new NotImplementedException(); case BinOp.Kind.Sub: return(dx0 - dx1); case BinOp.Kind.Xor: throw new NotImplementedException(); default: throw new NotImplementedException(); } }
private IAST expression() { IAST node = simpExpression(); if (tokenType() == Dictionary.LexemeType.relop) { Token t = lexer.token; lexer.consume(); node = new BinOp(node, t, simpExpression()); } return(node); }
private string GenerateExpr(Expression e) { return(e switch { BinOp binop => GenerateBinExpr(binop), UnOp unop => GenerateUnExpr(unop), ConstExpression constExpression => GenerateConstExpr(constExpression), VarExpression varExpression => GenerateVarExpr(varExpression), CallExpression callExpression => GenerateCallExpression(callExpression), ConditionalExpression conditionalExpression => GenerateConditionalExpression(conditionalExpression), _ => throw new CompilerException(e.GetType().ToString(), e.Row, e.Column) });
public object Visit_BinOp(BinOp node) { TreeViewItem item = new TreeViewItem(); item.IsExpanded = true; item.Header = node.Operation.Value; item.Items.Add(node.Left.Visit(this)); item.Items.Add(node.Right.Visit(this)); return(item); }
public int TransformBinOp(BinOp expr) { expr.Children[0].Accept(this); expr.Children[1].Accept(this); ExtractCILIndex(expr); XILInstr xi; switch (expr.Operation) { case BinOp.Kind.Add: xi = ISet.Add(); break; case BinOp.Kind.And: xi = ISet.And(); break; case BinOp.Kind.Concat: xi = ISet.Concat(); break; case BinOp.Kind.Div: xi = ISet.Div(); break; case BinOp.Kind.Eq: xi = ISet.IsEq(); break; case BinOp.Kind.Gt: xi = ISet.IsGt(); break; case BinOp.Kind.GtEq: xi = ISet.IsGte(); break; case BinOp.Kind.LShift: xi = ISet.LShift(); break; case BinOp.Kind.Lt: xi = ISet.IsLt(); break; case BinOp.Kind.LtEq: xi = ISet.IsLte(); break; case BinOp.Kind.Mul: xi = ISet.Mul(); break; case BinOp.Kind.NEq: xi = ISet.IsNEq(); break; case BinOp.Kind.Or: xi = ISet.Or(); break; case BinOp.Kind.Rem: xi = ISet.Rem(); break; case BinOp.Kind.RShift: xi = ISet.RShift(); break; case BinOp.Kind.Sub: xi = ISet.Sub(); break; case BinOp.Kind.Xor: xi = ISet.Xor(); break; case BinOp.Kind.Log: case BinOp.Kind.Exp: default: throw new NotImplementedException(); } Emit(xi, expr, 2, expr.ResultType); return(0); }
/// <summary> /// Helper method to clasify an operation as equality /// </summary> /// <param name="self">The operation to evaluate</param> /// <returns><c>true</c> if the operation is an equality operation; <c>false</c> otherwise</returns> public static bool IsEqualityOperation(this BinOp self) { switch (self) { case BinOp.Equal: case BinOp.NotEqual: return(true); default: return(false); } }
public Expression TransformBinOp(BinOp expr) { if (expr.IsConst()) { object result = expr.Eval(new DefaultEvaluator()); return(LiteralReference.CreateConstant(result)); } else { return(expr); } }
/// <summary> /// Helper method to clasify an operation as logical /// </summary> /// <param name="self">The operation to evaluate</param> /// <returns><c>true</c> if the operation is a logical operation; <c>false</c> otherwise</returns> public static bool IsLogicalOperation(this BinOp self) { switch (self) { case BinOp.LogicalAnd: case BinOp.LogicalOr: return(true); default: return(false); } }
public void Calc() { var square = new BinOp<long>(SimpleMath.SquareNumber); var factorial = new BinOp<int>(SimpleMath.Factorial); DisplayDelegateInfo(square); DisplayDelegateInfo(factorial); const long longNumber = 77214L; const int number = 7; Console.WriteLine("square of {0}: {1}", longNumber, square(longNumber)); Console.WriteLine("factorial of {0}: {1}", number, factorial.Invoke(number)); }
private IAST simpExpression() { IAST node = term(); while (tokenType() == Dictionary.LexemeType.add || tokenType() == Dictionary.LexemeType.sub) { Token t = lexer.token; lexer.consume(); node = new BinOp(node, t, term()); } return(node); }
private IAST term() { IAST node = factor(); while (tokenType() == Dictionary.LexemeType.mul || tokenType() == Dictionary.LexemeType.div) { Token t = lexer.token; lexer.consume(); node = new BinOp(node, t, factor()); } return(node); }
private AstNode Multiplicative() { var left = Unary(); while (new[] { TokenType.Mul, TokenType.Div, TokenType.Remainder }.Contains(_currentToken.Type)) { var op = _currentToken; Eat(op.Type); left = new BinOp(left, op, Unary()); } return(left); }
private AstNode Additive() { var left = Multiplicative(); while (new[] { TokenType.Plus, TokenType.Minus }.Contains(_currentToken.Type)) { var op = _currentToken; Eat(op.Type); left = new BinOp(left, op, Multiplicative()); } return(left); }
private AstNode LogicalOr() { var left = LogicalAnd(); while (_currentToken.Type == TokenType.LogicalOr) { var op = _currentToken; Eat(TokenType.LogicalOr); var right = LogicalAnd(); left = new BinOp(left, op, right); } return(left); }
public void visit(BinOp binOp) { binOp.left.accept(this); binOp.right.accept(this); switch (binOp.op) { case "+": binOp.output = binOp.left.output + binOp.right.output; break; case "-": binOp.output = binOp.left.output - binOp.right.output; break; case "*": binOp.output = binOp.left.output * binOp.right.output; break; case "/": binOp.output = binOp.left.output / binOp.right.output; break; case "<": binOp.output = binOp.left.output < binOp.right.output; break; case ">": binOp.output = binOp.left.output > binOp.right.output; break; case ">=": binOp.output = binOp.left.output >= binOp.right.output; break; case "<=": binOp.output = binOp.left.output >= binOp.right.output; break; case "<>": binOp.output = binOp.left.output != binOp.right.output; break; case "=": binOp.output = binOp.left.output == binOp.right.output; break; default: throw new Exception(" wrong operator: " + binOp.op); } }
public object VisitBinOp(BinOp node) { switch (node.Op.Type) { case TokenType.Plus: return(Visit(node.Left).Plus(Visit(node.Right))); case TokenType.Minus: return(Visit(node.Left).Minus(Visit(node.Right))); case TokenType.Mul: return(Visit(node.Left).Mul(Visit(node.Right))); case TokenType.Div: return(Visit(node.Left).Div(Visit(node.Right))); case TokenType.Remainder: return(Visit(node.Left).Mod(Visit(node.Right))); case TokenType.Assign: return(node.Left.Assign(Visit(node.Right), _currentContext)); case TokenType.LogicalAnd: return(Visit(node.Left).LogicalAnd(Visit(node.Right))); case TokenType.LogicalOr: return(Visit(node.Left).LogicalOr(Visit(node.Right))); case TokenType.Equals_: return(Visit(node.Left).Equals(Visit(node.Right))); case TokenType.NotEquals: return(!Visit(node.Left).Equals(Visit(node.Right))); case TokenType.Less: return(Visit(node.Left).LessThan(Visit(node.Right))); case TokenType.LessOrEquals: return(Visit(node.Left).LessEquals(Visit(node.Right))); case TokenType.Greater: return(Visit(node.Left).GreaterThan(Visit(node.Right))); case TokenType.GreaterOrEqual: return(Visit(node.Left).GreaterEquals(Visit(node.Right))); default: throw new Exception($"Unknown operator {node.Op.Type}"); } }
private void AddNext(BinOp op) { if (!(_prevElement is Variable || IsCloseBracket(_prevElement))) { throw new LogicException("Before binary operation can be only variable or open bracket."); } while (_operationsStack.Count > 0 && (_operationsStack.Peek() is BinOp prevOp && prevOp.Priority <= op.Priority || _operationsStack.Peek() is UnaryOp)) { _resultStack.Push(_operationsStack.Pop()); } _operationsStack.Push(op); }
static Node ParseRelExpression() { Node res = ParseExpression(); Node N2 = null; while (tokens.CurrentIsRel()) { string relation = tokens.Current.Type.ToString(); tokens.SelectNext(); N2 = ParseExpression(); res = new BinOp(relation, res, N2); } return(res); }
private AstNode BitwiseAnd() { var left = Equality(); while (_currentToken.Type == TokenType.BitwiseAnd) { var op = _currentToken; Eat(TokenType.BitwiseAnd); var right = Equality(); left = new BinOp(left, op, right); } return(left); }
private AstNode BitwiseOr() { var left = BitwiseXor(); while (_currentToken.Type == TokenType.BitwiseOr) { var op = _currentToken; Eat(TokenType.BitwiseOr); var right = BitwiseXor(); left = new BinOp(left, op, right); } return(left); }
public void VisitBinOp(BinOp n) { var result = new LinearRepresentation(operatorToOperation(n.Op)); n.Lhs.AcceptVisit(this); result.LeftOperand = idOrNum; n.Rhs.AcceptVisit(this); result.RightOperand = idOrNum; var identificator = new IdentificatorValue(CONSTANT_PREFIX + valueCounter++.ToString()); idOrNum = identificator; result.Destination = identificator; evaluatedExpression.Add(result); }
/// <summary> /// Helper method to clasify an operation as numeric /// </summary> /// <param name="self">The operation to evaluate</param> /// <returns><c>true</c> if the operation is a numeric operation; <c>false</c> otherwise</returns> public static bool IsNumericOperation(this BinOp self) { switch (self) { case BinOp.Add: case BinOp.Subtract: case BinOp.Multiply: case BinOp.Modulo: case BinOp.LessThanOrEqual: case BinOp.GreaterThan: case BinOp.GreaterThanOrEqual: return(true); default: return(false); } }
void print(BinOp exp) { Out.Write("BinOp "); switch (exp.Op) { case BINOP.Op.Plus: Out.Write('+'); break; case BINOP.Op.Minus: Out.Write('-'); break; case BINOP.Op.Times: Out.Write('*'); break; case BINOP.Op.Divide: Out.Write('/'); break; default: Out.Write(exp.Op); break; } Out.WriteLine(' ' + exp.Dst.ToString() + ' ' + exp.Left + ' ' + exp.Right); }
/// <summary> /// Transforms a binary expression. The default implementation clones it. /// </summary> /// <param name="expr">binary expression</param> /// <returns>transformation result</returns> public virtual Expression TransformBinOp(BinOp expr) { return expr.CloneThis(expr.Children.Select(e => e.Transform(this)).ToArray()); }
/// <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() }; }
private static void binop(SparseBitSet a, SparseBitSet b, BinOp op) { int nsize = a._size + b._size; long[] nbits; int [] noffs; int a_zero, a_size; // be very clever and avoid allocating more memory if we can. if (a.bits.Length < nsize) { // oh well, have to make working space. nbits = new long[nsize]; noffs = new int [nsize]; a_zero = 0; a_size = a._size; } else { // reduce, reuse, recycle! nbits = a.bits; noffs = a.offs; a_zero = a.bits.Length - a._size; a_size = a.bits.Length; // System.arraycopy(a.bits, 0, a.bits, a_zero, a.size); Array.Copy(a.bits,0,a.bits,a_zero,a._size); //System.arraycopy(a.offs, 0, a.offs, a_zero, a.size); Array.Copy(a.offs,0,a.offs,a_zero,a._size); } // ok, crunch through and binop those sets! nsize = 0; for (int i=a_zero, j=0; i<a_size || j<b._size; ) { long nb; int no; if (i<a_size && (j>=b._size || a.offs[i] < b.offs[j])) { nb = op.op(a.bits[i], 0); no = a.offs[i]; i++; } else if (j<b._size && (i>=a_size || a.offs[i] > b.offs[j])) { nb = op.op(0, b.bits[j]); no = b.offs[j]; j++; } else { // equal keys; merge. nb = op.op(a.bits[i], b.bits[j]); no = a.offs[i]; i++; j++; } if (nb!=0) { nbits[nsize] = nb; noffs[nsize] = no; nsize++; } } a.bits = nbits; a.offs = noffs; a._size = nsize; }
/// <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 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 }); }
public EOperatorAssociativity GetOperatorAssociativity(BinOp.Kind op) { switch (op) { case BinOp.Kind.Add: case BinOp.Kind.And: case BinOp.Kind.Concat: case BinOp.Kind.Mul: case BinOp.Kind.Or: case BinOp.Kind.Sub: case BinOp.Kind.Xor: return EOperatorAssociativity.LeftAssociative; case BinOp.Kind.Div: case BinOp.Kind.Eq: case BinOp.Kind.Exp: case BinOp.Kind.Gt: case BinOp.Kind.GtEq: case BinOp.Kind.Log: case BinOp.Kind.LShift: case BinOp.Kind.Lt: case BinOp.Kind.LtEq: case BinOp.Kind.Max: case BinOp.Kind.Min: case BinOp.Kind.NEq: case BinOp.Kind.Rem: case BinOp.Kind.RShift: return EOperatorAssociativity.UseParenthesis; default: throw new NotImplementedException(); } }
public int GetOperatorOrder(BinOp.Kind op) { switch (op) { case BinOp.Kind.Add: return 3; case BinOp.Kind.And: return 6; case BinOp.Kind.Concat: return 3; case BinOp.Kind.Div: return 1; case BinOp.Kind.Eq: return 5; case BinOp.Kind.Exp: return 0; case BinOp.Kind.Gt: return 5; case BinOp.Kind.GtEq: return 5; case BinOp.Kind.Log: return -1; case BinOp.Kind.LShift: return 4; case BinOp.Kind.Lt: return 5; case BinOp.Kind.LtEq: return 5; case BinOp.Kind.Mul: return 1; case BinOp.Kind.NEq: return 5; case BinOp.Kind.Or: return 6; case BinOp.Kind.Rem: return 1; case BinOp.Kind.RShift: return 4; case BinOp.Kind.Sub: return 3; case BinOp.Kind.Xor: return 6; default: throw new NotImplementedException(); } }
public NotateFunc GetNotation(BinOp.Kind op) { switch (op) { case BinOp.Kind.Add: return DefaultNotators.Infix("+"); case BinOp.Kind.And: return DefaultNotators.Infix("and"); case BinOp.Kind.Concat: return DefaultNotators.Infix("&"); case BinOp.Kind.Div: return DefaultNotators.Infix("/"); case BinOp.Kind.Eq: return DefaultNotators.Infix("="); case BinOp.Kind.Exp: return DefaultNotators.Infix("**"); case BinOp.Kind.Gt: return DefaultNotators.Infix(">"); case BinOp.Kind.GtEq: return DefaultNotators.Infix(">="); case BinOp.Kind.Log: return DefaultNotators.Function("LOG"); case BinOp.Kind.LShift: return DefaultNotators.Infix("sll"); case BinOp.Kind.Lt: return DefaultNotators.Infix("<"); case BinOp.Kind.LtEq: return DefaultNotators.Infix("<="); case BinOp.Kind.Mul: return DefaultNotators.Infix("*"); case BinOp.Kind.NEq: return DefaultNotators.Infix("/="); case BinOp.Kind.Or: return DefaultNotators.Infix("or"); case BinOp.Kind.Rem: return DefaultNotators.Infix("rem"); case BinOp.Kind.RShift: return DefaultNotators.Infix("srr"); case BinOp.Kind.Sub: return DefaultNotators.Infix("-"); case BinOp.Kind.Xor: return DefaultNotators.Infix("xor"); default: throw new NotImplementedException(); } }
// Simplified version public NotateFunc GetNotation(BinOp.Kind op) { switch (op) { case BinOp.Kind.Add: return DefaultNotators.Infix("+"); case BinOp.Kind.And: return DefaultNotators.Infix("&&"); case BinOp.Kind.Concat: return DefaultNotators.Function("concat"); case BinOp.Kind.Div: return DefaultNotators.Infix("/"); case BinOp.Kind.Eq: return DefaultNotators.Infix("=="); case BinOp.Kind.Exp: return DefaultNotators.Infix("pow"); // pow(a, b) ???? #include "math.h" !!!! case BinOp.Kind.Gt: return DefaultNotators.Infix(">"); case BinOp.Kind.GtEq: return DefaultNotators.Infix(">="); case BinOp.Kind.Log: return DefaultNotators.Function("log"); case BinOp.Kind.LShift: return DefaultNotators.Infix("<<"); case BinOp.Kind.Lt: return DefaultNotators.Infix("<"); case BinOp.Kind.LtEq: return DefaultNotators.Infix("<="); case BinOp.Kind.Mul: return DefaultNotators.Infix("*"); case BinOp.Kind.NEq: return DefaultNotators.Infix("!="); case BinOp.Kind.Or: return DefaultNotators.Infix("||"); case BinOp.Kind.Rem: return DefaultNotators.Infix("%"); case BinOp.Kind.RShift: return DefaultNotators.Infix(">>"); case BinOp.Kind.Sub: return DefaultNotators.Infix("-"); case BinOp.Kind.Xor: return DefaultNotators.Infix("^"); default: throw new NotImplementedException(); } }
public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder) { object[] vargs = args.Select(arg => arg.Sample).ToArray(); Expression[] eargs = args.Select(arg => arg.Expr).ToArray(); object sample = null; try { sample = callee.Invoke(vargs); } catch (Exception) { } Expression result = new BinOp() { Operation = Kind }; Array.Copy(eargs, result.Children, 2); if (sample != null) result.ResultType = TypeDescriptor.GetTypeOf(sample); else { Type rtype; callee.IsFunction(out rtype); result.ResultType = (TypeDescriptor)rtype; } stack.Push(result, sample); return true; }
public OpExpression(Expression left, BinOp op, Expression right) { this.left = left; this.op = op; this.right = right; }
private void genCodOp(BinOp op) { switch (op) { case BinOp.Sum: this.il.Emit(Emit.OpCodes.Add); break; case BinOp.Res: this.il.Emit(Emit.OpCodes.Sub); break; case BinOp.Mul: this.il.Emit(Emit.OpCodes.Mul); break; case BinOp.Div: this.il.Emit(Emit.OpCodes.Div); break; } }
/// <summary> /// Creates the attribute. /// </summary> /// <param name="kind">kind of binary operation</param> public MapToBinOp(BinOp.Kind kind) { Kind = kind; }
public EOperatorAssociativity GetOperatorAssociativity(BinOp.Kind op) { return EOperatorAssociativity.UseParenthesis; }