Take an equality-test expression that represents in-list
and munge it into the simpler thing we want to output
to the AbstractParsedStmt for its AbstractExpression classes.
17147
private void inFixup(VoltXMLElement inElement) {
        // make this an in expression
        inElement.name = "operation";
        inElement.attributes.put("optype", "in");

        VoltXMLElement rowElem = null;
        VoltXMLElement tableElem = null;
        VoltXMLElement subqueryElem = null;
        VoltXMLElement valueElem = null;
        for (VoltXMLElement child : inElement.children) {
            if (child.name.equals("row")) {
                rowElem = child;
            }
            else if (child.name.equals("table")) {
                tableElem = child;
            }
            else if (child.name.equals("tablesubquery")) {
                subqueryElem = child;
            }
            else if (child.name.equals("value")) {
                valueElem = child;
            }
        }

        VoltXMLElement inlist;
        if (tableElem != null) {
            // make the table expression an in-list
            inlist = new VoltXMLElement("vector");
            for (VoltXMLElement child : tableElem.children) {
                assert(child.name.equals("row"));
                assert(child.children.size() == 1);
                inlist.children.addAll(child.children);
            }
        }
        else if (subqueryElem != null) {
            inlist = subqueryElem;
        }
        else {
            assert valueElem != null;
            inlist = valueElem;
        }

        assert(rowElem != null);
        assert(inlist != null);
        inElement.children.clear();
        // add the row
        inElement.children.add(rowElem);
        // add the inlist
        inElement.children.add(inlist);
    }
650136
public static Predicate in(final String expr, final List<?> values) {

        return new Predicate() {

            private String sql;

            public void init(AbstractSqlCreator creator) {

                StringBuilder sb = new StringBuilder();
                sb.append(expr).append(" in (");

                boolean first = true;
                for (Object value : values) {
                    String param = creator.allocateParameter();
                    creator.setParameter(param, value);
                    if (!first) {
                        sb.append(", ");
                    }
                    sb.append(":").append(param);
                    first = false;
                }

                sb.append(")");

                sql = sb.toString();

            }

            public String toSql() {
                return sql;
            }
        };
    }
774013
@SuppressWarnings("unchecked")
	public <E> TerminalResult IN_list(E... value) {
		getPredicateExpression().setOperator(Operator.IN);
		getPredicateExpression().setValue_2(value);
		TerminalResult ret = APIAccess.createTerminalResult(this.getPredicateExpression());
		QueryRecorder.recordInvocation(this, "IN_list", ret, QueryRecorder.placeHolder(value));
		return ret;
	}
869183
public static Expression asList(Iterable<? extends Expression> items) {
    final ImmutableList<Expression> copy = ImmutableList.copyOf(items);
    if (copy.isEmpty()) {
      return MethodRef.IMMUTABLE_LIST_OF.get(0).invoke();
    }
    // Note, we cannot necessarily use ImmutableList for anything besides the empty list because
    // we may need to put a null in it.
    final Expression construct = ConstructorRef.ARRAY_LIST_SIZE.construct(constant(copy.size()));
    return new Expression(ARRAY_LIST_TYPE, Feature.NON_NULLABLE) {
      @Override
      protected void doGen(CodeBuilder mv) {
        construct.gen(mv);
        for (Expression child : copy) {
          mv.dup();
          child.gen(mv);
          MethodRef.ARRAY_LIST_ADD.invokeUnchecked(mv);
          mv.pop(); // pop the bool result of arraylist.add
        }
      }
    };
  }
722503
private Expression parseExpression(boolean acceptLists) {
        Expression expression = acceptLists ? parseAtomList() : parseAtom();
        while (tokenizer.more()) {
            if (tokenizer.current().isSymbol("+", "-")) {
                expression = new Operation(tokenizer.consume().getTrigger(), expression, parseAtom());
            } else if (tokenizer.current().isSymbol("*", "/", "%")) {
                String operation = tokenizer.consume().getTrigger();
                Expression next = parseAtom();
                expression = joinOperations(expression, operation, next);
            } else {
                if (tokenizer.current().isSymbol() && !tokenizer.current().isSymbol("!")) {
                    break;
                }
                ValueList list = new ValueList(false);
                list.add(expression);
                list.add(acceptLists ? parseAtomList() : parseAtom());
                expression = list;
            }
        }
        return expression;
    }
75972
private void evaluateExpressions() throws JspException {
        /*
         * Note: we don't check for type mismatches here; we assume
         * the expression evaluator will return the expected type
         * (by virtue of knowledge we give it about what that type is).
         * A ClassCastException here is truly unexpected, so we let it
         * propagate up.
         */

        if (begin_ != null) {
            Object r = ExpressionEvaluatorManager.evaluate(
                    "begin", begin_, Integer.class, this, pageContext);
            if (r == null) {
                throw new NullAttributeException("forTokens", "begin");
            }
            begin = ((Integer) r).intValue();
            validateBegin();
        }

        if (end_ != null) {
            Object r = ExpressionEvaluatorManager.evaluate(
                    "end", end_, Integer.class, this, pageContext);
            if (r == null) {
                throw new NullAttributeException("forTokens", "end");
            }
            end = ((Integer) r).intValue();
            validateEnd();
        }

        if (step_ != null) {
            Object r = ExpressionEvaluatorManager.evaluate(
                    "step", step_, Integer.class, this, pageContext);
            if (r == null) {
                throw new NullAttributeException("forTokens", "step");
            }
            step = ((Integer) r).intValue();
            validateStep();
        }

        if (items_ != null) {
            items = (String) ExpressionEvaluatorManager.evaluate(
                    "items", items_, String.class, this, pageContext);
            // use the empty string to indicate "no iteration"
            if (items == null) {
                items = "";
            }
        }

        if (delims_ != null) {
            delims = (String) ExpressionEvaluatorManager.evaluate(
                    "delims", delims_, String.class, this, pageContext);
            // use the empty string to cause monolithic tokenization
            if (delims == null) {
                delims = "";
            }
        }
    }
1060748
private void evaluateExpressions() throws JspException {
        /* 
         * Note: we don't check for type mismatches here; we assume
         * the expression evaluator will return the expected type
         * (by virtue of knowledge we give it about what that type is).
         * A ClassCastException here is truly unexpected, so we let it
         * propagate up.
         */

        if (begin_ != null) {
            Object r = ExpressionEvaluatorManager.evaluate(
                    "begin", begin_, Integer.class, this, pageContext);
            if (r == null) {
                throw new NullAttributeException("forEach", "begin");
            }
            begin = ((Integer) r).intValue();
            validateBegin();
        }

        if (end_ != null) {
            Object r = ExpressionEvaluatorManager.evaluate(
                    "end", end_, Integer.class, this, pageContext);
            if (r == null) {
                throw new NullAttributeException("forEach", "end");
            }
            end = ((Integer) r).intValue();
            validateEnd();
        }

        if (step_ != null) {
            Object r = ExpressionEvaluatorManager.evaluate(
                    "step", step_, Integer.class, this, pageContext);
            if (r == null) {
                throw new NullAttributeException("forEach", "step");
            }
            step = ((Integer) r).intValue();
            validateStep();
        }

        if (items_ != null) {
            rawItems = ExpressionEvaluatorManager.evaluate(
                    "items", items_, Object.class, this, pageContext);
            // use an empty list to indicate "no iteration", if relevant
            if (rawItems == null) {
                rawItems = new ArrayList();
            }
        }
    }
487050
public static String evaluateExpression(
				List<String> expressionToken, String[] delimiters,
				String[] validValues, String visibilityLevel, String display)
	{
		if ("visible".equals(visibilityLevel)) {
		display = (display == null || display.trim().isEmpty()) ? "" : "-" + display;
		}
		else {
			// hidden is not suffixed by -block, -inline or -inline-block
			display="";
		}
		String finalExpr = "";
		List<String> _valid = Arrays.asList(validValues);

		// Validate expression
		//
		// expression can be:
		// ONE SIZE: [size]
		// SIZE LIST: [size],[size],...,[size]
		// RANGE FROM: ...[size] or [size]... to get range (only inclusive)
		// RANGE BETWEEN: [size]...[size]

		// 1. Only one size:
		if(expressionToken.size() == 1)
		{
			finalExpr = " " + visibilityLevel + "-" + translateSize(expressionToken.get(0), true) + display;
		}
		// 2. Expression contains comma, so is a list of sizes
		else if (expressionToken.contains(","))
		{
			for(String ex: expressionToken) {
				if(",".equals(ex)) continue;

				finalExpr += " " + visibilityLevel + "-" + translateSize(ex, true) + display + " ";
			}
		}
		// 3. Expression is a range from
		else if (expressionToken.size() == 2) {
			if(expressionToken.get(0).equals("...")) {
				if(!_valid.contains(expressionToken.get(1)))
					throw new FacesException("Expression not valid. Valid syntax is ...[size] eg. ...sm . Valid sizes are [ xs, sm, md, lg ].");

				List<String> sR = getSizeRange("<=", translateSize(expressionToken.get(1), false));
				for(String s: sR) {
					finalExpr += " " + visibilityLevel + "-" + s + display + " ";
				}
			} else if(expressionToken.get(1).equals("...")) {
				if(!_valid.contains(expressionToken.get(0)))
					throw new FacesException("Expression not valid. Valid syntax is [size]... eg. sm... . Valid sizes are [ xs, sm, md, lg ].");

				List<String> sR = getSizeRange(">=", translateSize(expressionToken.get(0), false));
				for(String s: sR) {
					finalExpr += " " + visibilityLevel + "-" + s + display + " ";
				}
			} else {
				throw new FacesException("Expression not valid. Valid syntax is ...[size] or [size]... . Valid sizes are [ xs, sm, md, lg ].");
			}
		}
		// 4. Expression is in range
		else if(expressionToken.size() == 3) {
			// validation:
			if(!_valid.contains(expressionToken.get(0)) && !"...".equals(expressionToken.get(1)) && !_valid.contains(expressionToken.get(2)))
				throw new FacesException("Expression not valid. Valid syntax is [size]...[size] eg. xs...md . Valid sizes are [ xs, sm, md, lg ].");

			List<String> sR2 = getSizeRange(expressionToken.get(1), translateSize(expressionToken.get(0), false), translateSize(expressionToken.get(2), false));
			for(String s: sR2) {
				finalExpr += " " + visibilityLevel + "-" + s + display + " ";
			}
		}
		// 5. Otherwise
		else {
			throw new FacesException("Expression not valid. See the docs for a list of possibile rules.");
		}

		return finalExpr;
	}
586331
private PExp getImpliesExpression(AMapCompMapExp exp, ILexNameToken finmap,
			ILexNameToken findex)
	{
		if (exp.getPredicate() == null) // Map comprehension has no predicate
		{
			return getImpliesExists(exp, finmap, findex);
		} else
		{
			return AstExpressionFactory.newAImpliesBooleanBinaryExp(exp.getPredicate(), getImpliesExists(exp, finmap, findex));
		}
	}
849307
@Override
    public Object visitEqualityExpression(ExcellentParser.EqualityExpressionContext ctx) {
        Pair<Object, Object> args = Conversions.toSame(visit(ctx.expression(0)), visit(ctx.expression(1)), m_evalContext);
        boolean equal;

        if (args.getLeft() instanceof String) {
            // string equality is case-insensitive
            equal = ((String) args.getLeft()).equalsIgnoreCase((String) args.getRight());
        }
        else if (args.getLeft() instanceof BigDecimal) {
            // compareTo doesn't take scale into account
            equal = ((BigDecimal) args.getLeft()).compareTo((BigDecimal) args.getRight()) == 0;
        }
        else {
            equal = args.getLeft().equals(args.getRight());
        }

        return ctx.EQ() != null ? equal : !equal;
    }
414401
private static List<AbstractExpression> filterSingleTVEExpressions(List<AbstractExpression> exprs,
            List<AbstractExpression> otherExprs) {
        List<AbstractExpression> singleTVEExprs = new ArrayList<>();
        for (AbstractExpression expr : exprs) {
            List<TupleValueExpression> tves = ExpressionUtil.getTupleValueExpressions(expr);
            if (tves.size() == 1) {
                singleTVEExprs.add(expr);
            } else {
                otherExprs.add(expr);
            }
        }
        return singleTVEExprs;
    }
131197
public static <E> AbstractGroupExpression<E, SortedSet<E>> sortedSet(Expression<E> expression,
                                                                         Comparator<? super E> comparator) {
        return GSet.createSorted(expression, comparator);
    }
1037722
def _formulas(lexer, varname, fmt, nvars):
    """"""
    types = {IntegerToken, LPAREN} | _SAT_TOKS[fmt]
    tok = lexer.peek_token()
    if any(isinstance(tok, t) for t in types):
        first = _sat_formula(lexer, varname, fmt, nvars)
        rest = _formulas(lexer, varname, fmt, nvars)
        return (first, ) + rest
    # null
    else:
        return tuple()
84737
public static Expression transformListOfConstants(ListExpression origList, ClassNode attrType) {
        ListExpression newList = new ListExpression();
        boolean changed = false;
        for (Expression e : origList.getExpressions()) {
            try {
                Expression transformed = transformInlineConstants(e, attrType);
                newList.addExpression(transformed);
                if (transformed != e) changed = true;
            } catch(Exception ignored) {
                newList.addExpression(e);
            }
        }
        if (changed) {
            newList.setSourcePosition(origList);
            return newList;
        }
        return origList;
    }
361078
public static AbstractExpression buildEquavalenceExpression(Collection<AbstractExpression> leftExprs, Collection<AbstractExpression> rightExprs) {
        assert(leftExprs.size() == rightExprs.size());
        Iterator<AbstractExpression> leftIt = leftExprs.iterator();
        Iterator<AbstractExpression> rightIt = rightExprs.iterator();
        AbstractExpression result = null;
        while (leftIt.hasNext() && rightIt.hasNext()) {
            AbstractExpression leftExpr = leftIt.next();
            AbstractExpression rightExpr = rightIt.next();
            AbstractExpression eqaulityExpr = new ComparisonExpression(ExpressionType.COMPARE_EQUAL, leftExpr, rightExpr);
            if (result == null) {
                result = eqaulityExpr;
            } else {
                result = new ConjunctionExpression(ExpressionType.CONJUNCTION_AND, result, eqaulityExpr);
            }
        }
        return result;
    }
1354475
@Override
    public List<AbstractExpression> bindingToIndexedExpression(AbstractExpression expr) {
        if (equals(expr)) {
            return s_reusableImmutableEmptyBinding;
        }
        return null;
    }
1031966
public BooleanExpression in(T... right) {
        if (right.length == 1) {
            return eq(right[0]);
        } else {
            return Expressions.booleanOperation(Ops.IN, mixin, ConstantImpl.create(ImmutableList.copyOf(right)));
        }
    }