RAM: implemented magic method __lt__ for ASTNode to fix issues
    #88 and #209. The following test code works now, as does the test suite.
    import numexpr as ne
    a = 1 + 3j; b = 5.0
    ne.evaluate( 'a*2 + 15j - b' )
182816
def getConstants(ast):
    '''
    
    '''
    constants_order = sorted( ast.allOf('constant') )
    constants = [convertConstantToKind(a.value, a.astKind)
                 for a in constants_order]
    return constants_order, constants
59504
def get_memory_expr(self, address, size, mode="post"):
        
        mem = self.get_memory(mode)

        return smtfunction.concat(8, *reversed([mem[address + i] for i in range(size)]))
826201
private static double scalbn(double x, int n) {
        int hx = hi(x);
        int lx = lo(x);
        int k = (hx & 0x7ff00000) >> 20;         // extract exponent
        if (k == 0) {                          // 0 or subnormal x
            if ((lx | (hx & 0x7fffffff)) == 0) {
                return x; // +-0
            }
            x *= two54;
            hx = hi(x);
            k = ((hx & 0x7ff00000) >> 20) - 54;
            if (n < -50000) {
                return tiny * x;                   // underflow
            }
        }
        if (k == 0x7ff) {
            return x + x;                        // NaN or Inf
        }
        k = k + n;
        if (k > 0x7fe) {
            return huge * copysign(huge, x);      // overflow
        }
        if (k > 0) {
            // normal result
            return fromhilo((hx & 0x800fffff) | (k << 20), lo(x));
        }
        if (k <= -54) {
            if (n > 50000) {
                // in case integer overflow in n+k
                return huge * copysign(huge, x);  // overflow
            }
            else {
                return tiny * copysign(tiny, x);    // underflow
            }
        }
        k += 54;                             // subnormal result
        x = fromhilo((hx & 0x800fffff) | (k << 20), lo(x));
        return x * twom54;
    }
222632
function changeExprCompareExprs(changeExpr, exprs, data) {
    for (var i = 0, l = exprs.length; i < l; i++) {
        if (changeExprCompare(changeExpr, exprs[i], data)) {
            return 1;
        }
    }

    return 0;
}
712624
def visit_Expr(self, node: AST, dfltChaining: bool = True) -> str:
        """"""
        return self.visit(node.value)
1164397
def visit_Num(self, node: AST, dfltChaining: bool = True) -> str:
        """"""
        return str(node.n)
1280444
function computeTopLevelExpressions(ast) {
        var exprDepth = 0;
        var exprDepthStack = [];
        var topLevelExprs = [];
        var visitorIdentifyTopLevelExprPre = {
            "CallExpression":function (node) {
                if (node.callee.type === 'MemberExpression' &&
                    node.callee.object.type === 'Identifier' &&
                    node.callee.object.name === JALANGI_VAR) {
                    var funName = node.callee.property.name;
                    if ((exprDepth === 0 &&
                        (funName === 'A' ||
                            funName === 'P' ||
                            funName === 'G' ||
                            funName === 'R' ||
                            funName === 'W' ||
                            funName === 'H' ||
                            funName === 'T' ||
                            funName === 'Rt' ||
                            funName === 'B' ||
                            funName === 'U' ||
                            funName === 'C' ||
                            funName === 'C1' ||
                            funName === 'C2'
                            )) ||
                        (exprDepth === 1 &&
                            (funName === 'F' ||
                                funName === 'M'))) {
                        topLevelExprs.push(node.arguments[0].value);
                    }
                    exprDepth++;
                } else if (node.callee.type === 'CallExpression' &&
                    node.callee.callee.type === 'MemberExpression' &&
                    node.callee.callee.object.type === 'Identifier' &&
                    node.callee.callee.object.name === JALANGI_VAR &&
                    (node.callee.callee.property.name === 'F' ||
                        node.callee.callee.property.name === 'M')) {
                    exprDepth++;
                }
            },
            "FunctionExpression":function (node, context) {
                exprDepthStack.push(exprDepth);
                exprDepth = 0;
            },
            "FunctionDeclaration":function (node) {
                exprDepthStack.push(exprDepth);
                exprDepth = 0;
            }

        };

        var visitorIdentifyTopLevelExprPost = {
            "CallExpression":function (node) {
                if (node.callee.type === 'MemberExpression' &&
                    node.callee.object.type === 'Identifier' &&
                    node.callee.object.name === JALANGI_VAR) {
                    exprDepth--;
                } else if (node.callee.type === 'CallExpression' &&
                    node.callee.callee.type === 'MemberExpression' &&
                    node.callee.callee.object.type === 'Identifier' &&
                    node.callee.callee.object.name === JALANGI_VAR &&
                    (node.callee.callee.property.name === 'F' ||
                        node.callee.callee.property.name === 'M')) {
                    exprDepth--;
                }
                return node;
            },
            "FunctionExpression":function (node, context) {
                exprDepth = exprDepthStack.pop();
                return node;
            },
            "FunctionDeclaration":function (node) {
                exprDepth = exprDepthStack.pop();
                return node;
            }
        };
        transformAst(ast, visitorIdentifyTopLevelExprPost, visitorIdentifyTopLevelExprPre, CONTEXT.RHS);
        return topLevelExprs;
    }
567086
def numprop(value, propertyexpected):
    
    if propertyexpected == 'triangular':
        x = (math.sqrt(8 * value + 1) - 1) / 2
        return bool(x - int(x) > 0)
    elif propertyexpected == 'square':
        return math.sqrt(value).is_integer()
    elif propertyexpected == 'cube':
        x = value**(1 / 3)
        x = int(round(x))
        return bool(x**3 == value)
    elif propertyexpected == 'even':
        return value % 2 == 0
    elif propertyexpected == 'odd':
        return not value % 2 == 0
    elif propertyexpected == 'positive':
        return bool(value > 0)
    elif propertyexpected == 'negative':
        return bool(value < 0)
    elif propertyexpected == 'zero':
        return bool(value == 0)
96155
function bnpToRadix(b) {
    if (b == null) b = 10;
    if (this.signum() === 0 || b < 2 || b > 36) return "0";
    var cs = this.chunkSize(b);
    var a = Math.pow(b, cs);
    var d = nbv(a), y = nbi(), z = nbi(), r = "";
    this.divRemTo(d, y, z);
    while (y.signum() > 0) {
        r = (a + z.intValue()).toString(b).substr(1) + r;
        y.divRemTo(d, y, z);
    }
    return z.intValue().toString(b) + r;
}
600958
private Node performArithmeticOp(Token opType, Node left, Node right) {
    // Unlike other operations, ADD operands are not always converted
    // to Number.
    if (opType == Token.ADD
        && (NodeUtil.mayBeString(left, shouldUseTypes)
            || NodeUtil.mayBeString(right, shouldUseTypes))) {
      return null;
    }

    double result;

    // TODO(johnlenz): Handle NaN with unknown value. BIT ops convert NaN
    // to zero so this is a little awkward here.

    Double lValObj = NodeUtil.getNumberValue(left);
    Double rValObj = NodeUtil.getNumberValue(right);
    // at least one of the two operands must have a value and both must be numeric
    if ((lValObj == null && rValObj == null) || !isNumeric(left) || !isNumeric(right)) {
      return null;
    }
    // handle the operations that have algebraic identities, since we can simplify the tree without
    // actually knowing the value statically.
    switch (opType) {
      case ADD:
        if (lValObj != null && rValObj != null) {
          return maybeReplaceBinaryOpWithNumericResult(lValObj + rValObj, lValObj, rValObj);
        }
        if (lValObj != null && lValObj == 0) {
          return right.cloneTree(true);
        } else if (rValObj != null && rValObj == 0) {
          return left.cloneTree(true);
        }
        return null;
      case SUB:
        if (lValObj != null && rValObj != null) {
          return maybeReplaceBinaryOpWithNumericResult(lValObj - rValObj, lValObj, rValObj);
        }
        if (lValObj != null && lValObj == 0) {
          // 0 - x -> -x
          return IR.neg(right.cloneTree(true));
        } else if (rValObj != null && rValObj == 0) {
          // x - 0 -> x
          return left.cloneTree(true);
        }
        return null;
      case MUL:
        if (lValObj != null && rValObj != null) {
          return maybeReplaceBinaryOpWithNumericResult(lValObj * rValObj, lValObj, rValObj);
        }
        // NOTE: 0*x != 0 for all x, if x==0, then it is NaN.  So we can't take advantage of that
        // without some kind of non-NaN proof.  So the special cases here only deal with 1*x
        if (lValObj != null) {
          if (lValObj == 1) {
            return right.cloneTree(true);
          }
        } else {
          if (rValObj == 1) {
            return left.cloneTree(true);
          }
        }
        return null;
      case DIV:
        if (lValObj != null && rValObj != null) {
          if (rValObj == 0) {
            return null;
          }
          return maybeReplaceBinaryOpWithNumericResult(lValObj / rValObj, lValObj, rValObj);
        }
        // NOTE: 0/x != 0 for all x, if x==0, then it is NaN
        if (rValObj != null) {
          if (rValObj == 1) {
            // x/1->x
            return left.cloneTree(true);
          }
        }
        return null;
      case EXPONENT:
        if (lValObj != null && rValObj != null) {
          return maybeReplaceBinaryOpWithNumericResult(
              Math.pow(lValObj, rValObj), lValObj, rValObj);
        }
        return null;
      default:
        // fall-through
    }
    if (lValObj == null || rValObj == null) {
      return null;
    }
    double lval = lValObj;
    double rval = rValObj;
    switch (opType) {
      case BITAND:
        result = NodeUtil.toInt32(lval) & NodeUtil.toInt32(rval);
        break;
      case BITOR:
        result = NodeUtil.toInt32(lval) | NodeUtil.toInt32(rval);
        break;
      case BITXOR:
        result = NodeUtil.toInt32(lval) ^ NodeUtil.toInt32(rval);
        break;
      case MOD:
        if (rval == 0) {
          return null;
        }
        result = lval % rval;
        break;
      default:
        throw new Error("Unexpected arithmetic operator: " + opType);
    }
    return maybeReplaceBinaryOpWithNumericResult(result, lval, rval);
  }
1182737
@Override
  public Tree evaluate(Tree t, TregexMatcher m) {
    newNodeNames = new HashMap<String,Tree>();
    coindexer.setLastIndex(t);
    for (TsurgeonPattern child : children) {
      t = child.evaluate(t, m);
      if (t == null) {
        return null;
      }
    }
    return t;
  }
376070
def p_jr(p):
    
    p[4] = Expr.makenode(Container('-', p.lineno(3)), p[4], Expr.makenode(Container(MEMORY.org + 2, p.lineno(1))))
    p[0] = Asm(p.lineno(1), 'JR %s,N' % p[2], p[4])
1093527
function verifyMathExpressions(expression, node) {
        if (expression.type === "MathExpression") {
          const { operator, left, right } = expression;

          if (operator === "+" || operator === "-") {
            if (
              expression.source.operator.end.index === right.source.start.index
            ) {
              complain(
                messages.expectedSpaceAfterOperator(operator),
                node.sourceIndex + expression.source.operator.end.index
              );
            }

            if (
              expression.source.operator.start.index === left.source.end.index
            ) {
              complain(
                messages.expectedSpaceBeforeOperator(operator),
                node.sourceIndex + expression.source.operator.start.index
              );
            }
          } else if (operator === "/") {
            if (
              (right.type === "Value" && right.value === 0) ||
              (right.type === "MathExpression" && getNumber(right) === 0)
            ) {
              complain(
                messages.rejectedDivisionByZero(),
                node.sourceIndex + expression.source.operator.end.index
              );
            }
          }

          if (getResolvedType(expression) === "invalid") {
            complain(
              messages.expectedValidResolvedType(operator),
              node.sourceIndex + expression.source.operator.start.index
            );
          }

          verifyMathExpressions(expression.left, node);
          verifyMathExpressions(expression.right, node);
        }
      }
393125
def build_ast(expression, debug = False):
    """"""
    #use a directed graph to store the tree
    G = DiGraph()
    stack = []


    for n in expression:
        # Since the graph does not maintain the order of adding nodes/edges
        # add an extra attribute 'pos' so we can always sort to the correct order
        if isinstance(n,OperatorNode):
            if n.ttype == "operator-infix":
                arg2 = stack.pop()
                arg1 = stack.pop()
                # Hack to write the name of sheet in 2argument address
                if(n.tvalue == ':'):
                    if '!' in arg1.tvalue and arg2.ttype == 'operand' and '!' not in arg2.tvalue:
                        arg2.tvalue = arg1.tvalue.split('!')[0] + '!' + arg2.tvalue

                G.add_node(arg1,pos = 1)
                G.add_node(arg2,pos = 2)
                G.add_edge(arg1, n)
                G.add_edge(arg2, n)
            else:
                arg1 = stack.pop()
                G.add_node(arg1,pos = 1)
                G.add_edge(arg1, n)

        elif isinstance(n,FunctionNode):
            args = []
            for _ in range(n.num_args):
                try:
                    args.append(stack.pop())
                except:
                    raise Exception()
            #try:
                # args = [stack.pop() for _ in range(n.num_args)]
            #except:
            #        print 'STACK', stack, type(n)
            #        raise Exception('prut')
            args.reverse()
            for i,a in enumerate(args):
                G.add_node(a,pos = i)
                G.add_edge(a,n)
        else:
            G.add_node(n,pos=0)

        stack.append(n)

    return G,stack.pop()
1165963
def process_mod_line_num(self, data, name, idx, num_type='hex', aux=None):
        
        try:
            num = 0
            if num_type == 'base64':
                num = int(base64.b16encode(base64.b64decode(data)), 16)
            elif num_type == 'hex':
                num = int(strip_hex_prefix(data), 16)
            elif num_type == 'dec':
                num = int(data)
            else:
                raise ValueError('Unknown number format: %s' % num_type)

            js = collections.OrderedDict()
            js['type'] = 'mod-%s' % num_type
            js['fname'] = name
            js['idx'] = idx
            js['aux'] = aux
            js['n'] = '0x%x' % num

            if self.has_fingerprint(num):
                logger.warning('Fingerprint found in modulus %s idx %s ' % (name, idx))
                self.mark_and_add_effort(num, js)

                if self.do_print:
                    print(json.dumps(js))
            return TestResult(js)

        except Exception as e:
            logger.debug('Exception in testing modulus %s idx %s : %s data: %s' % (name, idx, e, data[:30]))
            self.trace_logger.log(e)
362154
private SqlNode getNthExpr(SqlNode query, int ordinal, int sourceCount) {
		if (query instanceof SqlInsert) {
			SqlInsert insert = (SqlInsert) query;
			if (insert.getTargetColumnList() != null) {
				return insert.getTargetColumnList().get(ordinal);
			} else {
				return getNthExpr(
					insert.getSource(),
					ordinal,
					sourceCount);
			}
		} else if (query instanceof SqlUpdate) {
			SqlUpdate update = (SqlUpdate) query;
			if (update.getTargetColumnList() != null) {
				return update.getTargetColumnList().get(ordinal);
			} else if (update.getSourceExpressionList() != null) {
				return update.getSourceExpressionList().get(ordinal);
			} else {
				return getNthExpr(
					update.getSourceSelect(),
					ordinal,
					sourceCount);
			}
		} else if (query instanceof SqlSelect) {
			SqlSelect select = (SqlSelect) query;
			if (select.getSelectList().size() == sourceCount) {
				return select.getSelectList().get(ordinal);
			} else {
				return query; // give up
			}
		} else {
			return query; // give up
		}
	}
894596
private BigInteger evalUnaryExpression(AstNode exprAst) {
    // only 'unary-operator cast-expression' production is allowed in #if-context

    AstNode operator = exprAst.getFirstChild();
    AstNode operand = operator.getNextSibling();
    AstNodeType operatorType = operator.getFirstChild().getType();

    if (operatorType.equals(CppPunctuator.PLUS)) {
      return evalToInt(operand);
    } else if (operatorType.equals(CppPunctuator.MINUS)) {
      return evalToInt(operand).negate();
    } else if (operatorType.equals(CppPunctuator.NOT)) {
      boolean result = !evalToBoolean(operand);
      return result ? BigInteger.ONE : BigInteger.ZERO;
    } else if (operatorType.equals(CppPunctuator.BW_NOT)) {
      //todo: need more information (signed/unsigned, data type length) to invert bits in all cases correct
      return evalToInt(operand).not().and(UINT64_MAX);
    } else {
      throw new EvaluationException("Unknown unary operator  '" + operatorType + "'");
    }
  }