Search in sources :

Example 1 with UnaryExpression

use of com.github.anba.es6draft.ast.UnaryExpression in project es6draft by anba.

the class SwitchStatementGenerator method intSwitchEntries.

private static long[] intSwitchEntries(List<SwitchClause> clauses, boolean hasDefault) {
    long[] entries = new long[clauses.size() - (hasDefault ? 1 : 0)];
    for (int i = 0, j = 0, size = clauses.size(); i < size; ++i) {
        Expression expr = clauses.get(i).getExpression();
        if (expr != null) {
            int value;
            if (expr instanceof NumericLiteral) {
                value = ((NumericLiteral) expr).intValue();
            } else {
                value = -((NumericLiteral) ((UnaryExpression) expr).getOperand()).intValue();
            }
            entries[j++] = Entry(value, i);
        }
    }
    // sort values in ascending order
    Arrays.sort(entries);
    return entries;
}
Also used : NumericLiteral(com.github.anba.es6draft.ast.NumericLiteral) BinaryExpression(com.github.anba.es6draft.ast.BinaryExpression) UnaryExpression(com.github.anba.es6draft.ast.UnaryExpression) Expression(com.github.anba.es6draft.ast.Expression)

Aggregations

BinaryExpression (com.github.anba.es6draft.ast.BinaryExpression)1 Expression (com.github.anba.es6draft.ast.Expression)1 NumericLiteral (com.github.anba.es6draft.ast.NumericLiteral)1 UnaryExpression (com.github.anba.es6draft.ast.UnaryExpression)1