public OrderingSpecification getOrdering(IdNode lhs, LiteralNode rhs, String operator, int order) {
if (lhs.getWidthBits() == -1 || lhs.getDivisionBits() == -1 || !(rhs.getValue() instanceof Long)) {
return null;
}
if (operator.equals("==") || operator.equals("=")) {
return new OrderingSpecification(order, (Long)rhs.getValue(), lhs.getWidthBits(), lhs.getDivisionBits());
}
if (order == OrderingSpecification.ASCENDING) {
if ((operator.equals("<") || operator.equals("<="))) {
return new OrderingSpecification(order, 0, lhs.getWidthBits(), lhs.getDivisionBits());
}
if (operator.equals(">")) {
return new OrderingSpecification(order, (Long)rhs.getValue() + 1, lhs.getWidthBits(), lhs.getDivisionBits());
}
if (operator.equals(">=")) {
return new OrderingSpecification(order, (Long)rhs.getValue(), lhs.getWidthBits(), lhs.getDivisionBits());
}
} else {
if (operator.equals("<")) {
return new OrderingSpecification(order, (Long)rhs.getValue() - 1, lhs.getWidthBits(), lhs.getDivisionBits());
}
if (operator.equals("<=")) {
return new OrderingSpecification(order, (Long)rhs.getValue(), lhs.getWidthBits(), lhs.getDivisionBits());
}
}
return null;
}