jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode Java Examples

The following examples show how to use jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FinalizeTypes.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public boolean enterLiteralNode(final LiteralNode literalNode) {
    if (literalNode instanceof ArrayLiteralNode) {
        final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode;
        final Expression[]     array            = arrayLiteralNode.getValue();
        final Type             elementType      = arrayLiteralNode.getElementType();

        for (int i = 0; i < array.length; i++) {
            final Node element = array[i];
            if (element != null) {
                array[i] = convert((Expression)element.accept(this), elementType);
            }
        }
    }

    return false;
}
 
Example #2
Source File: Lower.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterASSIGN(BinaryNode binaryNode) {
    if (es6 && (binaryNode.lhs() instanceof ObjectNode || binaryNode.lhs() instanceof ArrayLiteralNode)) {
        throwNotImplementedYet("es6.destructuring", binaryNode);
    }
    return super.enterASSIGN(binaryNode);
}
 
Example #3
Source File: WeighNodes.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public boolean enterLiteralNode(final LiteralNode literalNode) {
    weight += LITERAL_WEIGHT;

    if (literalNode instanceof ArrayLiteralNode) {
        final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode;
        final Node[]           value            = arrayLiteralNode.getValue();
        final int[]            postsets         = arrayLiteralNode.getPostsets();
        final List<ArrayUnit>  units            = arrayLiteralNode.getUnits();

        if (units == null) {
            for (final int postset : postsets) {
                weight += AASTORE_WEIGHT;
                final Node element = value[postset];

                if (element != null) {
                    element.accept(this);
                }
            }
        }

        return false;
    }

    return true;
}
 
Example #4
Source File: WeighNodes.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public boolean enterLiteralNode(final LiteralNode literalNode) {
    weight += LITERAL_WEIGHT;

    if (literalNode instanceof ArrayLiteralNode) {
        final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode;
        final Node[]           value            = arrayLiteralNode.getValue();
        final int[]            postsets         = arrayLiteralNode.getPostsets();
        final List<Splittable.SplitRange>  units            = arrayLiteralNode.getSplitRanges();

        if (units == null) {
            for (final int postset : postsets) {
                weight += AASTORE_WEIGHT;
                final Node element = value[postset];

                if (element != null) {
                    element.accept(this);
                }
            }
        }

        return false;
    }

    return true;
}
 
Example #5
Source File: LocalVariableTypesCalculator.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterLiteralNode(final LiteralNode<?> literalNode) {
    if (literalNode instanceof ArrayLiteralNode) {
        final List<Expression> expressions = ((ArrayLiteralNode)literalNode).getElementExpressions();
        if (expressions != null) {
            visitExpressions(expressions);
        }
    }
    pushExpressionType(literalNode);
    return false;
}
 
Example #6
Source File: ReplaceCompileUnits.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveLiteralNode(final LiteralNode<?> node) {
    if (node instanceof ArrayLiteralNode) {
        final ArrayLiteralNode aln = (ArrayLiteralNode)node;
        if (aln.getSplitRanges() == null) {
            return node;
        }
        final List<Splittable.SplitRange> newArrayUnits = new ArrayList<>();
        for (final Splittable.SplitRange au : aln.getSplitRanges()) {
            newArrayUnits.add(new Splittable.SplitRange(getExistingReplacement(au), au.getLow(), au.getHigh()));
        }
        return aln.setSplitRanges(lc, newArrayUnits);
    }
    return node;
}
 
Example #7
Source File: WeighNodes.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public boolean enterLiteralNode(final LiteralNode literalNode) {
    weight += LITERAL_WEIGHT;

    if (literalNode instanceof ArrayLiteralNode) {
        final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode;
        final Node[]           value            = arrayLiteralNode.getValue();
        final int[]            postsets         = arrayLiteralNode.getPostsets();
        final List<ArrayUnit>  units            = arrayLiteralNode.getUnits();

        if (units == null) {
            for (final int postset : postsets) {
                weight += AASTORE_WEIGHT;
                final Node element = value[postset];

                if (element != null) {
                    element.accept(this);
                }
            }
        }

        return false;
    }

    return true;
}
 
Example #8
Source File: WeighNodes.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public boolean enterLiteralNode(final LiteralNode literalNode) {
    weight += LITERAL_WEIGHT;

    if (literalNode instanceof ArrayLiteralNode) {
        final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode;
        final Node[]           value            = arrayLiteralNode.getValue();
        final int[]            postsets         = arrayLiteralNode.getPostsets();
        final List<ArrayUnit>  units            = arrayLiteralNode.getUnits();

        if (units == null) {
            for (final int postset : postsets) {
                weight += AASTORE_WEIGHT;
                final Node element = value[postset];

                if (element != null) {
                    element.accept(this);
                }
            }
        }

        return false;
    }

    return true;
}
 
Example #9
Source File: WeighNodes.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public boolean enterLiteralNode(final LiteralNode literalNode) {
    weight += LITERAL_WEIGHT;

    if (literalNode instanceof ArrayLiteralNode) {
        final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode;
        final Node[]           value            = arrayLiteralNode.getValue();
        final int[]            postsets         = arrayLiteralNode.getPostsets();
        final List<Splittable.SplitRange>  units            = arrayLiteralNode.getSplitRanges();

        if (units == null) {
            for (final int postset : postsets) {
                weight += AASTORE_WEIGHT;
                final Node element = value[postset];

                if (element != null) {
                    element.accept(this);
                }
            }
        }

        return false;
    }

    return true;
}
 
Example #10
Source File: LocalVariableTypesCalculator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterLiteralNode(final LiteralNode<?> literalNode) {
    if (literalNode instanceof ArrayLiteralNode) {
        final List<Expression> expressions = ((ArrayLiteralNode)literalNode).getElementExpressions();
        if (expressions != null) {
            visitExpressions(expressions);
        }
    }
    pushExpressionType(literalNode);
    return false;
}
 
Example #11
Source File: ReplaceCompileUnits.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveLiteralNode(final LiteralNode<?> node) {
    if (node instanceof ArrayLiteralNode) {
        final ArrayLiteralNode aln = (ArrayLiteralNode)node;
        if (aln.getSplitRanges() == null) {
            return node;
        }
        final List<Splittable.SplitRange> newArrayUnits = new ArrayList<>();
        for (final Splittable.SplitRange au : aln.getSplitRanges()) {
            newArrayUnits.add(new Splittable.SplitRange(getExistingReplacement(au), au.getLow(), au.getHigh()));
        }
        return aln.setSplitRanges(lc, newArrayUnits);
    }
    return node;
}
 
Example #12
Source File: WeighNodes.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public boolean enterLiteralNode(final LiteralNode literalNode) {
    if (literalNode instanceof LiteralNode.PrimitiveLiteralNode) {
        weight += CONST_WEIGHT;
        return false;
    }

    weight += LITERAL_WEIGHT;

    if (literalNode instanceof ArrayLiteralNode) {
        final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode;
        final Node[]           value            = arrayLiteralNode.getValue();
        final int[]            postsets         = arrayLiteralNode.getPostsets();
        final List<Splittable.SplitRange>  units            = arrayLiteralNode.getSplitRanges();

        if (units == null) {
            for (final int postset : postsets) {
                weight += AASTORE_WEIGHT;
                final Node element = value[postset];

                if (element != null) {
                    element.accept(this);
                }
            }
        }

        return false;
    }

    return true;
}
 
Example #13
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterLiteralNode(final LiteralNode<?> literalNode) {
    if (literalNode instanceof ArrayLiteralNode) {
        final List<Expression> expressions = ((ArrayLiteralNode)literalNode).getElementExpressions();
        if (expressions != null) {
            visitExpressions(expressions);
        }
    }
    pushExpressionType(literalNode);
    return false;
}
 
Example #14
Source File: ReplaceCompileUnits.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveLiteralNode(final LiteralNode<?> node) {
    if (node instanceof ArrayLiteralNode) {
        final ArrayLiteralNode aln = (ArrayLiteralNode)node;
        if (aln.getSplitRanges() == null) {
            return node;
        }
        final List<Splittable.SplitRange> newArrayUnits = new ArrayList<>();
        for (final Splittable.SplitRange au : aln.getSplitRanges()) {
            newArrayUnits.add(new Splittable.SplitRange(getExistingReplacement(au), au.getLow(), au.getHigh()));
        }
        return aln.setSplitRanges(lc, newArrayUnits);
    }
    return node;
}
 
Example #15
Source File: Lower.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterForNode(final ForNode forNode) {
    if (es6 && (forNode.getInit() instanceof ObjectNode || forNode.getInit() instanceof ArrayLiteralNode)) {
        throwNotImplementedYet("es6.destructuring", forNode);
    }
    return super.enterForNode(forNode);
}
 
Example #16
Source File: ReplaceCompileUnits.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveLiteralNode(final LiteralNode<?> node) {
    if (node instanceof ArrayLiteralNode) {
        final ArrayLiteralNode aln = (ArrayLiteralNode)node;
        if (aln.getSplitRanges() == null) {
            return node;
        }
        final List<Splittable.SplitRange> newArrayUnits = new ArrayList<>();
        for (final Splittable.SplitRange au : aln.getSplitRanges()) {
            newArrayUnits.add(new Splittable.SplitRange(getExistingReplacement(au), au.getLow(), au.getHigh()));
        }
        return aln.setSplitRanges(lc, newArrayUnits);
    }
    return node;
}
 
Example #17
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterLiteralNode(final LiteralNode<?> literalNode) {
    if (literalNode instanceof ArrayLiteralNode) {
        final List<Expression> expressions = ((ArrayLiteralNode)literalNode).getElementExpressions();
        if (expressions != null) {
            visitExpressions(expressions);
        }
    }
    pushExpressionType(literalNode);
    return false;
}
 
Example #18
Source File: WeighNodes.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public boolean enterLiteralNode(final LiteralNode literalNode) {
    weight += LITERAL_WEIGHT;

    if (literalNode instanceof ArrayLiteralNode) {
        final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode;
        final Node[]           value            = arrayLiteralNode.getValue();
        final int[]            postsets         = arrayLiteralNode.getPostsets();
        final List<Splittable.SplitRange>  units            = arrayLiteralNode.getSplitRanges();

        if (units == null) {
            for (final int postset : postsets) {
                weight += AASTORE_WEIGHT;
                final Node element = value[postset];

                if (element != null) {
                    element.accept(this);
                }
            }
        }

        return false;
    }

    return true;
}
 
Example #19
Source File: ReplaceCompileUnits.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveLiteralNode(final LiteralNode<?> node) {
    if (node instanceof ArrayLiteralNode) {
        final ArrayLiteralNode aln = (ArrayLiteralNode)node;
        if (aln.getSplitRanges() == null) {
            return node;
        }
        final List<Splittable.SplitRange> newArrayUnits = new ArrayList<>();
        for (final Splittable.SplitRange au : aln.getSplitRanges()) {
            newArrayUnits.add(new Splittable.SplitRange(getExistingReplacement(au), au.getLow(), au.getHigh()));
        }
        return aln.setSplitRanges(lc, newArrayUnits);
    }
    return node;
}
 
Example #20
Source File: WeighNodes.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public boolean enterLiteralNode(final LiteralNode literalNode) {
    weight += LITERAL_WEIGHT;

    if (literalNode instanceof ArrayLiteralNode) {
        final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode;
        final Node[]           value            = arrayLiteralNode.getValue();
        final int[]            postsets         = arrayLiteralNode.getPostsets();
        final List<Splittable.SplitRange>  units            = arrayLiteralNode.getSplitRanges();

        if (units == null) {
            for (final int postset : postsets) {
                weight += AASTORE_WEIGHT;
                final Node element = value[postset];

                if (element != null) {
                    element.accept(this);
                }
            }
        }

        return false;
    }

    return true;
}
 
Example #21
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterLiteralNode(final LiteralNode<?> literalNode) {
    if (literalNode instanceof ArrayLiteralNode) {
        final List<Expression> expressions = ((ArrayLiteralNode)literalNode).getElementExpressions();
        if (expressions != null) {
            visitExpressions(expressions);
        }
    }
    pushExpressionType(literalNode);
    return false;
}
 
Example #22
Source File: LocalVariableTypesCalculator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterLiteralNode(final LiteralNode<?> literalNode) {
    if (literalNode instanceof ArrayLiteralNode) {
        final List<Expression> expressions = ((ArrayLiteralNode)literalNode).getElementExpressions();
        if (expressions != null) {
            visitExpressions(expressions);
        }
    }
    pushExpressionType(literalNode);
    return false;
}
 
Example #23
Source File: ReplaceCompileUnits.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveLiteralNode(final LiteralNode<?> node) {
    if (node instanceof ArrayLiteralNode) {
        final ArrayLiteralNode aln = (ArrayLiteralNode)node;
        if (aln.getSplitRanges() == null) {
            return node;
        }
        final List<Splittable.SplitRange> newArrayUnits = new ArrayList<>();
        for (final Splittable.SplitRange au : aln.getSplitRanges()) {
            newArrayUnits.add(new Splittable.SplitRange(getExistingReplacement(au), au.getLow(), au.getHigh()));
        }
        return aln.setSplitRanges(lc, newArrayUnits);
    }
    return node;
}
 
Example #24
Source File: WeighNodes.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public boolean enterLiteralNode(final LiteralNode literalNode) {
    weight += LITERAL_WEIGHT;

    if (literalNode instanceof ArrayLiteralNode) {
        final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode;
        final Node[]           value            = arrayLiteralNode.getValue();
        final int[]            postsets         = arrayLiteralNode.getPostsets();
        final List<ArrayUnit>  units            = arrayLiteralNode.getUnits();

        if (units == null) {
            for (final int postset : postsets) {
                weight += AASTORE_WEIGHT;
                final Node element = value[postset];

                if (element != null) {
                    element.accept(this);
                }
            }
        }

        return false;
    }

    return true;
}
 
Example #25
Source File: WeighNodes.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public boolean enterLiteralNode(final LiteralNode literalNode) {
    weight += LITERAL_WEIGHT;

    if (literalNode instanceof ArrayLiteralNode) {
        final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode;
        final Node[]           value            = arrayLiteralNode.getValue();
        final int[]            postsets         = arrayLiteralNode.getPostsets();
        final List<Splittable.SplitRange>  units            = arrayLiteralNode.getSplitRanges();

        if (units == null) {
            for (final int postset : postsets) {
                weight += AASTORE_WEIGHT;
                final Node element = value[postset];

                if (element != null) {
                    element.accept(this);
                }
            }
        }

        return false;
    }

    return true;
}
 
Example #26
Source File: ReplaceCompileUnits.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveLiteralNode(final LiteralNode<?> node) {
    if (node instanceof ArrayLiteralNode) {
        final ArrayLiteralNode aln = (ArrayLiteralNode)node;
        if (aln.getUnits() == null) {
            return node;
        }
        final List<ArrayUnit> newArrayUnits = new ArrayList<>();
        for (final ArrayUnit au : aln.getUnits()) {
            newArrayUnits.add(new ArrayUnit(getExistingReplacement(au), au.getLo(), au.getHi()));
        }
        return aln.setUnits(lc, newArrayUnits);
    }
    return node;
}
 
Example #27
Source File: LocalVariableTypesCalculator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterLiteralNode(final LiteralNode<?> literalNode) {
    if (literalNode instanceof ArrayLiteralNode) {
        final List<Expression> expressions = ((ArrayLiteralNode)literalNode).getElementExpressions();
        if (expressions != null) {
            visitExpressions(expressions);
        }
    }
    pushExpressionType(literalNode);
    return false;
}
 
Example #28
Source File: AssignSymbols.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isSplitArray(final LexicalContextNode expr) {
    if(!(expr instanceof ArrayLiteralNode)) {
        return false;
    }
    final List<ArrayUnit> units = ((ArrayLiteralNode)expr).getUnits();
    return !(units == null || units.isEmpty());
}
 
Example #29
Source File: FoldConstants.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected LiteralNode<?> eval() {
    final Node rhsNode = parent.getExpression();

    if (!(rhsNode instanceof LiteralNode)) {
        return null;
    }

    if (rhsNode instanceof ArrayLiteralNode) {
        return null;
    }

    final LiteralNode<?> rhs = (LiteralNode<?>)rhsNode;
    final Type rhsType = rhs.getType();
    final boolean rhsInteger = rhsType.isInteger() || rhsType.isBoolean();

    LiteralNode<?> literalNode;

    switch (parent.tokenType()) {
    case ADD:
        if (rhsInteger) {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getInt32());
        } else if (rhsType.isLong()) {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getLong());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, rhs.getNumber());
        }
        break;
    case SUB:
        if (rhsInteger && rhs.getInt32() != 0) { // @see test/script/basic/minuszero.js
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getInt32());
        } else if (rhsType.isLong() && rhs.getLong() != 0L) {
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getLong());
        } else {
            literalNode = LiteralNode.newInstance(token, finish, -rhs.getNumber());
        }
        break;
    case NOT:
        literalNode = LiteralNode.newInstance(token, finish, !rhs.getBoolean());
        break;
    case BIT_NOT:
        literalNode = LiteralNode.newInstance(token, finish, ~rhs.getInt32());
        break;
    default:
        return null;
    }

    return literalNode;
}
 
Example #30
Source File: CodeGenerator.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Load a list of nodes as an array of a specific type
 * The array will contain the visited nodes.
 *
 * @param arrayLiteralNode the array of contents
 * @param arrayType        the type of the array, e.g. ARRAY_NUMBER or ARRAY_OBJECT
 *
 * @return the method generator that was used
 */
private MethodEmitter loadArray(final ArrayLiteralNode arrayLiteralNode, final ArrayType arrayType) {
    assert arrayType == Type.INT_ARRAY || arrayType == Type.LONG_ARRAY || arrayType == Type.NUMBER_ARRAY || arrayType == Type.OBJECT_ARRAY;

    final Expression[]    nodes    = arrayLiteralNode.getValue();
    final Object          presets  = arrayLiteralNode.getPresets();
    final int[]           postsets = arrayLiteralNode.getPostsets();
    final Class<?>        type     = arrayType.getTypeClass();
    final List<ArrayUnit> units    = arrayLiteralNode.getUnits();

    loadConstant(presets);

    final Type elementType = arrayType.getElementType();

    if (units != null) {
        final MethodEmitter savedMethod     = method;
        final FunctionNode  currentFunction = lc.getCurrentFunction();

        for (final ArrayUnit arrayUnit : units) {
            unit = lc.pushCompileUnit(arrayUnit.getCompileUnit());

            final String className = unit.getUnitClassName();
            final String name      = currentFunction.uniqueName(SPLIT_PREFIX.symbolName());
            final String signature = methodDescriptor(type, ScriptFunction.class, Object.class, ScriptObject.class, type);

            final MethodEmitter me = unit.getClassEmitter().method(EnumSet.of(Flag.PUBLIC, Flag.STATIC), name, signature);
            method = lc.pushMethodEmitter(me);

            method.setFunctionNode(currentFunction);
            method.begin();

            fixScopeSlot(currentFunction);

            method.load(arrayType, SPLIT_ARRAY_ARG.slot());

            for (int i = arrayUnit.getLo(); i < arrayUnit.getHi(); i++) {
                storeElement(nodes, elementType, postsets[i]);
            }

            method._return();
            method.end();
            method = lc.popMethodEmitter(me);

            assert method == savedMethod;
            method.loadCompilerConstant(CALLEE);
            method.swap();
            method.loadCompilerConstant(THIS);
            method.swap();
            method.loadCompilerConstant(SCOPE);
            method.swap();
            method.invokestatic(className, name, signature);

            unit = lc.popCompileUnit(unit);
        }

        return method;
    }

    for (final int postset : postsets) {
        storeElement(nodes, elementType, postset);
    }

    return method;
}