Java Code Examples for jdk.nashorn.internal.ir.Symbol#isParam()

The following examples show how to use jdk.nashorn.internal.ir.Symbol#isParam() . 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: Attr.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveReturnNode(final ReturnNode returnNode) {
    final Expression expr = returnNode.getExpression();
    final Type returnType;

    if (expr != null) {
        //we can't do parameter specialization if we return something that hasn't been typed yet
        final Symbol symbol = expr.getSymbol();
        if (expr.getType().isUnknown() && symbol.isParam()) {
            symbol.setType(Type.OBJECT);
        }

        returnType = widestReturnType(returnTypes.pop(), symbol.getSymbolType());
    } else {
        returnType = Type.OBJECT; //undefined
    }
    LOG.info("Returntype is now ", returnType);
    returnTypes.push(returnType);

    end(returnNode);

    return returnNode;
}
 
Example 2
Source File: Attr.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveReturnNode(final ReturnNode returnNode) {
    final Expression expr = returnNode.getExpression();
    final Type returnType;

    if (expr != null) {
        //we can't do parameter specialization if we return something that hasn't been typed yet
        final Symbol symbol = expr.getSymbol();
        if (expr.getType().isUnknown() && symbol.isParam()) {
            symbol.setType(Type.OBJECT);
        }

        returnType = widestReturnType(returnTypes.pop(), symbol.getSymbolType());
    } else {
        returnType = Type.OBJECT; //undefined
    }
    LOG.info("Returntype is now ", returnType);
    returnTypes.push(returnType);

    end(returnNode);

    return returnNode;
}
 
Example 3
Source File: MapCreator.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compute property flags given local state of a field. May be overridden and extended,
 *
 * @param symbol       symbol to check
 * @param hasArguments does the created object have an "arguments" property
 *
 * @return flags to use for fields
 */
protected int getPropertyFlags(final Symbol symbol, final boolean hasArguments) {
    int flags = 0;

    if (symbol.isParam()) {
        flags |= Property.IS_ALWAYS_OBJECT | Property.IS_PARAMETER;
    }

    if (hasArguments) {
        flags |= Property.IS_ALWAYS_OBJECT | Property.HAS_ARGUMENTS;
    }

    if (symbol.isScope()) {
        flags |= Property.NOT_CONFIGURABLE;
    }

    if (symbol.canBePrimitive()) {
        flags |= Property.CAN_BE_PRIMITIVE;
    }

    if (symbol.canBeUndefined()) {
        flags |= Property.CAN_BE_UNDEFINED;
    }

    return flags;
}
 
Example 4
Source File: FieldObjectCreator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tally the number of fields and parameters.
 */
private void countFields() {
    for (final Symbol symbol : this.symbols) {
        if (symbol != null) {
            if (hasArguments() && symbol.isParam()) {
                symbol.setFieldIndex(paramCount++);
            } else {
                symbol.setFieldIndex(fieldCount++);
            }
        }
    }

    paddedFieldCount = getPaddedFieldCount(fieldCount);
}
 
Example 5
Source File: MapCreator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compute property flags given local state of a field. May be overridden and extended,
 *
 * @param symbol       symbol to check
 * @param hasArguments does the created object have an "arguments" property
 *
 * @return flags to use for fields
 */
protected int getPropertyFlags(final Symbol symbol, final boolean hasArguments) {
    int flags = 0;

    if (symbol.isParam()) {
        flags |= Property.IS_ALWAYS_OBJECT | Property.IS_PARAMETER;
    }

    if (hasArguments) {
        flags |= Property.IS_ALWAYS_OBJECT | Property.HAS_ARGUMENTS;
    }

    if (symbol.isScope()) {
        flags |= Property.NOT_CONFIGURABLE;
    }

    if (symbol.canBePrimitive()) {
        flags |= Property.CAN_BE_PRIMITIVE;
    }

    if (symbol.canBeUndefined()) {
        flags |= Property.CAN_BE_UNDEFINED;
    }

    if (symbol.isFunctionDeclaration()) {
        flags |= Property.IS_FUNCTION_DECLARATION;
    }

    return flags;
}
 
Example 6
Source File: FieldObjectCreator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tally the number of fields and parameters.
 */
private void countFields() {
    for (final MapTuple<T> tuple : tuples) {
        final Symbol symbol = tuple.symbol;
        if (symbol != null) {
            if (hasArguments() && symbol.isParam()) {
                symbol.setFieldIndex(paramCount++);
            } else if (!isValidArrayIndex(getArrayIndex(tuple.key))) {
                symbol.setFieldIndex(fieldCount++);
            }
        }
    }

    paddedFieldCount = getPaddedFieldCount(fieldCount);
}
 
Example 7
Source File: FieldObjectCreator.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tally the number of fields and parameters.
 */
private void countFields() {
    for (final MapTuple<T> tuple : tuples) {
        final Symbol symbol = tuple.symbol;
        if (symbol != null) {
            if (hasArguments() && symbol.isParam()) {
                symbol.setFieldIndex(paramCount++);
            } else if (!isValidArrayIndex(getArrayIndex(tuple.key))) {
                symbol.setFieldIndex(fieldCount++);
            }
        }
    }

    paddedFieldCount = getPaddedFieldCount(fieldCount);
}
 
Example 8
Source File: FieldObjectCreator.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tally the number of fields and parameters.
 */
private void countFields() {
    for (final Symbol symbol : this.symbols) {
        if (symbol != null) {
            if (hasArguments() && symbol.isParam()) {
                symbol.setFieldIndex(paramCount++);
            } else {
                symbol.setFieldIndex(fieldCount++);
            }
        }
    }

    paddedFieldCount = getPaddedFieldCount(fieldCount);
}
 
Example 9
Source File: FieldObjectCreator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tally the number of fields and parameters.
 */
private void countFields() {
    for (final Symbol symbol : this.symbols) {
        if (symbol != null) {
            if (hasArguments() && symbol.isParam()) {
                symbol.setFieldIndex(paramCount++);
            } else {
                symbol.setFieldIndex(fieldCount++);
            }
        }
    }

    paddedFieldCount = getPaddedFieldCount(fieldCount);
}
 
Example 10
Source File: Attr.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void ensureTypeNotUnknown(final Expression node) {

        final Symbol symbol = node.getSymbol();

        LOG.info("Ensure type not unknown for: ", symbol);

        /*
         * Note that not just unknowns, but params need to be blown
         * up to objects, because we can have something like
         *
         * function f(a) {
         *    var b = ~a; //b and a are inferred to be int
         *    return b;
         * }
         *
         * In this case, it would be correct to say that "if you have
         * an int at the callsite, just pass it".
         *
         * However
         *
         * function f(a) {
         *    var b = ~a;      //b and a are inferred to be int
         *    return b == 17;  //b is still inferred to be int.
         * }
         *
         * can be called with f("17") and if we assume that b is an
         * int and don't blow it up to an object in the comparison, we
         * are screwed. I hate JavaScript.
         *
         * This check has to be done for any operation that might take
         * objects as parameters, for example +, but not *, which is known
         * to coerce types into doubles
         */
        if (node.getType().isUnknown() || (symbol.isParam() && !symbol.isSpecializedParam())) {
            newType(symbol, Type.OBJECT);
            symbol.setCanBeUndefined();
         }
    }
 
Example 11
Source File: Attr.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void newType(final Symbol symbol, final Type type) {
    final Type oldType = symbol.getSymbolType();
    symbol.setType(type);

    if (symbol.getSymbolType() != oldType) {
        LOG.info("New TYPE ", type, " for ", symbol," (was ", oldType, ")");
    }

    if (symbol.isParam()) {
        symbol.setType(type);
        LOG.info("Param type change ", symbol);
    }
}
 
Example 12
Source File: FieldObjectCreator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tally the number of fields and parameters.
 */
private void countFields() {
    for (final MapTuple<T> tuple : tuples) {
        final Symbol symbol = tuple.symbol;
        if (symbol != null) {
            if (hasArguments() && symbol.isParam()) {
                symbol.setFieldIndex(paramCount++);
            } else if (!isValidArrayIndex(getArrayIndex(tuple.key))) {
                symbol.setFieldIndex(fieldCount++);
            }
        }
    }

    paddedFieldCount = getPaddedFieldCount(fieldCount);
}
 
Example 13
Source File: FieldObjectCreator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tally the number of fields and parameters.
 */
private void countFields() {
    for (final MapTuple<T> tuple : tuples) {
        final Symbol symbol = tuple.symbol;
        if (symbol != null) {
            if (hasArguments() && symbol.isParam()) {
                symbol.setFieldIndex(paramCount++);
            } else if (!isValidArrayIndex(getArrayIndex(tuple.key))) {
                symbol.setFieldIndex(fieldCount++);
            }
        }
    }

    paddedFieldCount = getPaddedFieldCount(fieldCount);
}
 
Example 14
Source File: Attr.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static void newType(final Symbol symbol, final Type type) {
    final Type oldType = symbol.getSymbolType();
    symbol.setType(type);

    if (symbol.getSymbolType() != oldType) {
        LOG.info("New TYPE ", type, " for ", symbol," (was ", oldType, ")");
    }

    if (symbol.isParam()) {
        symbol.setType(type);
        LOG.info("Param type change ", symbol);
    }
}
 
Example 15
Source File: FieldObjectCreator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tally the number of fields and parameters.
 */
private void countFields() {
    for (final MapTuple<T> tuple : tuples) {
        final Symbol symbol = tuple.symbol;
        if (symbol != null) {
            if (hasArguments() && symbol.isParam()) {
                symbol.setFieldIndex(paramCount++);
            } else if (!isValidArrayIndex(getArrayIndex(tuple.key))) {
                symbol.setFieldIndex(fieldCount++);
            }
        }
    }

    paddedFieldCount = getPaddedFieldCount(fieldCount);
}
 
Example 16
Source File: AssignSymbols.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isParamOrVar(final IdentNode identNode) {
    final Symbol symbol = identNode.getSymbol();
    return symbol.isParam() || symbol.isVar();
}
 
Example 17
Source File: AssignSymbols.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isParamOrVar(final IdentNode identNode) {
    final Symbol symbol = identNode.getSymbol();
    return symbol.isParam() || symbol.isVar();
}
 
Example 18
Source File: AssignSymbols.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isParamOrVar(final IdentNode identNode) {
    final Symbol symbol = identNode.getSymbol();
    return symbol.isParam() || symbol.isVar();
}
 
Example 19
Source File: MapCreator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute property flags given local state of a field. May be overridden and extended,
 *
 * @param symbol       symbol to check
 * @param hasArguments does the created object have an "arguments" property
 *
 * @return flags to use for fields
 */
static int getPropertyFlags(final Symbol symbol, final boolean hasArguments, final boolean evalCode, final boolean dualFields) {
    int flags = 0;

    if (symbol.isParam()) {
        flags |= Property.IS_PARAMETER;
    }

    if (hasArguments) {
        flags |= Property.HAS_ARGUMENTS;
    }

    // See ECMA 5.1 10.5 Declaration Binding Instantiation.
    // Step 2  If code is eval code, then let configurableBindings
    // be true else let configurableBindings be false.
    // We have to make vars, functions declared in 'eval' code
    // configurable. But vars, functions from any other code is
    // not configurable.
    if (symbol.isScope() && !evalCode) {
        flags |= Property.NOT_CONFIGURABLE;
    }

    if (symbol.isFunctionDeclaration()) {
        flags |= Property.IS_FUNCTION_DECLARATION;
    }

    if (symbol.isConst()) {
        flags |= Property.NOT_WRITABLE;
    }

    if (symbol.isBlockScoped()) {
        flags |= Property.IS_LEXICAL_BINDING;
    }

    // Mark symbol as needing declaration. Access before declaration will throw a ReferenceError.
    if (symbol.isBlockScoped() && symbol.isScope()) {
        flags |= Property.NEEDS_DECLARATION;
    }

    if (dualFields) {
        flags |= Property.DUAL_FIELDS;
    }

    return flags;
}
 
Example 20
Source File: MapCreator.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute property flags given local state of a field. May be overridden and extended,
 *
 * @param symbol       symbol to check
 * @param hasArguments does the created object have an "arguments" property
 *
 * @return flags to use for fields
 */
static int getPropertyFlags(final Symbol symbol, final boolean hasArguments, final boolean evalCode, final boolean dualFields) {
    int flags = 0;

    if (symbol.isParam()) {
        flags |= Property.IS_PARAMETER;
    }

    if (hasArguments) {
        flags |= Property.HAS_ARGUMENTS;
    }

    // See ECMA 5.1 10.5 Declaration Binding Instantiation.
    // Step 2  If code is eval code, then let configurableBindings
    // be true else let configurableBindings be false.
    // We have to make vars, functions declared in 'eval' code
    // configurable. But vars, functions from any other code is
    // not configurable.
    if (symbol.isScope() && !evalCode) {
        flags |= Property.NOT_CONFIGURABLE;
    }

    if (symbol.isFunctionDeclaration()) {
        flags |= Property.IS_FUNCTION_DECLARATION;
    }

    if (symbol.isConst()) {
        flags |= Property.NOT_WRITABLE;
    }

    if (symbol.isBlockScoped()) {
        flags |= Property.IS_LEXICAL_BINDING;
    }

    // Mark symbol as needing declaration. Access before declaration will throw a ReferenceError.
    if (symbol.isBlockScoped() && symbol.isScope()) {
        flags |= Property.NEEDS_DECLARATION;
    }

    if (dualFields) {
        flags |= Property.DUAL_FIELDS;
    }

    return flags;
}