Java Code Examples for jdk.nashorn.internal.ir.IdentNode#setIsDeclaredHere()

The following examples show how to use jdk.nashorn.internal.ir.IdentNode#setIsDeclaredHere() . 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: Parser.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * VariableStatement :
 *      var VariableDeclarationList ;
 *
 * VariableDeclarationList :
 *      VariableDeclaration
 *      VariableDeclarationList , VariableDeclaration
 *
 * VariableDeclaration :
 *      Identifier Initializer?
 *
 * Initializer :
 *      = AssignmentExpression
 *
 * See 12.2
 *
 * Parse a VAR statement.
 * @param isStatement True if a statement (not used in a FOR.)
 */
private List<VarNode> variableStatement(final TokenType varType, final boolean isStatement) {
    // VAR tested in caller.
    next();

    final List<VarNode> vars = new ArrayList<>();
    int varFlags = 0;
    if (varType == LET) {
        varFlags |= VarNode.IS_LET;
    } else if (varType == CONST) {
        varFlags |= VarNode.IS_CONST;
    }

    while (true) {
        // Get starting token.
        final int  varLine  = line;
        final long varToken = token;
        // Get name of var.
        final IdentNode name = getIdent();
        verifyStrictIdent(name, "variable name");

        // Assume no init.
        Expression init = null;

        // Look for initializer assignment.
        if (type == ASSIGN) {
            next();

            // Get initializer expression. Suppress IN if not statement.
            defaultNames.push(name);
            try {
                init = assignmentExpression(!isStatement);
            } finally {
                defaultNames.pop();
            }
        } else if (varType == CONST) {
            throw error(AbstractParser.message("missing.const.assignment", name.getName()));
        }

        // Allocate var node.
        final VarNode var = new VarNode(varLine, varToken, finish, name.setIsDeclaredHere(), init, varFlags);
        vars.add(var);
        appendStatement(var);

        if (type != COMMARIGHT) {
            break;
        }
        next();
    }

    // If is a statement then handle end of line.
    if (isStatement) {
        final boolean semicolon = type == SEMICOLON;
        endOfLine();
        if (semicolon) {
            lc.getCurrentBlock().setFinish(finish);
        }
    }

    return vars;
}
 
Example 2
Source File: Parser.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * VariableStatement :
 *      var VariableDeclarationList ;
 *
 * VariableDeclarationList :
 *      VariableDeclaration
 *      VariableDeclarationList , VariableDeclaration
 *
 * VariableDeclaration :
 *      Identifier Initializer?
 *
 * Initializer :
 *      = AssignmentExpression
 *
 * See 12.2
 *
 * Parse a VAR statement.
 * @param isStatement True if a statement (not used in a FOR.)
 */
private List<VarNode> variableStatement(final TokenType varType, final boolean isStatement) {
    // VAR tested in caller.
    next();

    final List<VarNode> vars = new ArrayList<>();
    int varFlags = 0;
    if (varType == LET) {
        varFlags |= VarNode.IS_LET;
    } else if (varType == CONST) {
        varFlags |= VarNode.IS_CONST;
    }

    while (true) {
        // Get starting token.
        final int  varLine  = line;
        final long varToken = token;
        // Get name of var.
        final IdentNode name = getIdent();
        verifyStrictIdent(name, "variable name");

        // Assume no init.
        Expression init = null;

        // Look for initializer assignment.
        if (type == ASSIGN) {
            next();

            // Get initializer expression. Suppress IN if not statement.
            defaultNames.push(name);
            try {
                init = assignmentExpression(!isStatement);
            } finally {
                defaultNames.pop();
            }
        } else if (varType == CONST) {
            throw error(AbstractParser.message("missing.const.assignment", name.getName()));
        }

        // Allocate var node.
        final VarNode var = new VarNode(varLine, varToken, finish, name.setIsDeclaredHere(), init, varFlags);
        vars.add(var);
        appendStatement(var);

        if (type != COMMARIGHT) {
            break;
        }
        next();
    }

    // If is a statement then handle end of line.
    if (isStatement) {
        final boolean semicolon = type == SEMICOLON;
        endOfLine();
        if (semicolon) {
            lc.getCurrentBlock().setFinish(finish);
        }
    }

    return vars;
}
 
Example 3
Source File: Parser.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * VariableStatement :
 *      var VariableDeclarationList ;
 *
 * VariableDeclarationList :
 *      VariableDeclaration
 *      VariableDeclarationList , VariableDeclaration
 *
 * VariableDeclaration :
 *      Identifier Initializer?
 *
 * Initializer :
 *      = AssignmentExpression
 *
 * See 12.2
 *
 * Parse a VAR statement.
 * @param isStatement True if a statement (not used in a FOR.)
 */
private List<VarNode> variableStatement(final TokenType varType, final boolean isStatement) {
    // VAR tested in caller.
    next();

    final List<VarNode> vars = new ArrayList<>();
    int varFlags = 0;
    if (varType == LET) {
        varFlags |= VarNode.IS_LET;
    } else if (varType == CONST) {
        varFlags |= VarNode.IS_CONST;
    }

    while (true) {
        // Get starting token.
        final int  varLine  = line;
        final long varToken = token;
        // Get name of var.
        final IdentNode name = getIdent();
        verifyStrictIdent(name, "variable name");

        // Assume no init.
        Expression init = null;

        // Look for initializer assignment.
        if (type == ASSIGN) {
            next();

            // Get initializer expression. Suppress IN if not statement.
            defaultNames.push(name);
            try {
                init = assignmentExpression(!isStatement);
            } finally {
                defaultNames.pop();
            }
        } else if (varType == CONST) {
            throw error(AbstractParser.message("missing.const.assignment", name.getName()));
        }

        // Allocate var node.
        final VarNode var = new VarNode(varLine, varToken, finish, name.setIsDeclaredHere(), init, varFlags);
        vars.add(var);
        appendStatement(var);

        if (type != COMMARIGHT) {
            break;
        }
        next();
    }

    // If is a statement then handle end of line.
    if (isStatement) {
        final boolean semicolon = type == SEMICOLON;
        endOfLine();
        if (semicolon) {
            lc.getCurrentBlock().setFinish(finish);
        }
    }

    return vars;
}
 
Example 4
Source File: Parser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * VariableStatement :
 *      var VariableDeclarationList ;
 *
 * VariableDeclarationList :
 *      VariableDeclaration
 *      VariableDeclarationList , VariableDeclaration
 *
 * VariableDeclaration :
 *      Identifier Initializer?
 *
 * Initializer :
 *      = AssignmentExpression
 *
 * See 12.2
 *
 * Parse a VAR statement.
 * @param isStatement True if a statement (not used in a FOR.)
 */
private List<VarNode> variableStatement(final TokenType varType, final boolean isStatement) {
    // VAR tested in caller.
    next();

    final List<VarNode> vars = new ArrayList<>();
    int varFlags = 0;
    if (varType == LET) {
        varFlags |= VarNode.IS_LET;
    } else if (varType == CONST) {
        varFlags |= VarNode.IS_CONST;
    }

    while (true) {
        // Get starting token.
        final int  varLine  = line;
        final long varToken = token;
        // Get name of var.
        final IdentNode name = getIdent();
        verifyStrictIdent(name, "variable name");

        // Assume no init.
        Expression init = null;

        // Look for initializer assignment.
        if (type == ASSIGN) {
            next();

            // Get initializer expression. Suppress IN if not statement.
            defaultNames.push(name);
            try {
                init = assignmentExpression(!isStatement);
            } finally {
                defaultNames.pop();
            }
        } else if (varType == CONST) {
            throw error(AbstractParser.message("missing.const.assignment", name.getName()));
        }

        // Allocate var node.
        final VarNode var = new VarNode(varLine, varToken, finish, name.setIsDeclaredHere(), init, varFlags);
        vars.add(var);
        appendStatement(var);

        if (type != COMMARIGHT) {
            break;
        }
        next();
    }

    // If is a statement then handle end of line.
    if (isStatement) {
        final boolean semicolon = type == SEMICOLON;
        endOfLine();
        if (semicolon) {
            lc.getCurrentBlock().setFinish(finish);
        }
    }

    return vars;
}
 
Example 5
Source File: Parser.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * VariableStatement :
 *      var VariableDeclarationList ;
 *
 * VariableDeclarationList :
 *      VariableDeclaration
 *      VariableDeclarationList , VariableDeclaration
 *
 * VariableDeclaration :
 *      Identifier Initializer?
 *
 * Initializer :
 *      = AssignmentExpression
 *
 * See 12.2
 *
 * Parse a VAR statement.
 * @param isStatement True if a statement (not used in a FOR.)
 */
private List<VarNode> variableStatement(final TokenType varType, final boolean isStatement) {
    // VAR tested in caller.
    next();

    final List<VarNode> vars = new ArrayList<>();
    int varFlags = 0;
    if (varType == LET) {
        varFlags |= VarNode.IS_LET;
    } else if (varType == CONST) {
        varFlags |= VarNode.IS_CONST;
    }

    while (true) {
        // Get starting token.
        final int  varLine  = line;
        final long varToken = token;
        // Get name of var.
        final IdentNode name = getIdent();
        verifyStrictIdent(name, "variable name");

        // Assume no init.
        Expression init = null;

        // Look for initializer assignment.
        if (type == ASSIGN) {
            next();

            // Get initializer expression. Suppress IN if not statement.
            defaultNames.push(name);
            try {
                init = assignmentExpression(!isStatement);
            } finally {
                defaultNames.pop();
            }
        } else if (varType == CONST) {
            throw error(AbstractParser.message("missing.const.assignment", name.getName()));
        }

        // Allocate var node.
        final VarNode var = new VarNode(varLine, varToken, finish, name.setIsDeclaredHere(), init, varFlags);
        vars.add(var);
        appendStatement(var);

        if (type != COMMARIGHT) {
            break;
        }
        next();
    }

    // If is a statement then handle end of line.
    if (isStatement) {
        final boolean semicolon = type == SEMICOLON;
        endOfLine();
        if (semicolon) {
            lc.getCurrentBlock().setFinish(finish);
        }
    }

    return vars;
}
 
Example 6
Source File: Parser.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * VariableStatement :
 *      var VariableDeclarationList ;
 *
 * VariableDeclarationList :
 *      VariableDeclaration
 *      VariableDeclarationList , VariableDeclaration
 *
 * VariableDeclaration :
 *      Identifier Initializer?
 *
 * Initializer :
 *      = AssignmentExpression
 *
 * See 12.2
 *
 * Parse a VAR statement.
 * @param isStatement True if a statement (not used in a FOR.)
 */
private List<VarNode> variableStatement(final TokenType varType, final boolean isStatement) {
    // VAR tested in caller.
    next();

    final List<VarNode> vars = new ArrayList<>();
    int varFlags = 0;
    if (varType == LET) {
        varFlags |= VarNode.IS_LET;
    } else if (varType == CONST) {
        varFlags |= VarNode.IS_CONST;
    }

    while (true) {
        // Get starting token.
        final int  varLine  = line;
        final long varToken = token;
        // Get name of var.
        final IdentNode name = getIdent();
        verifyStrictIdent(name, "variable name");

        // Assume no init.
        Expression init = null;

        // Look for initializer assignment.
        if (type == ASSIGN) {
            next();

            // Get initializer expression. Suppress IN if not statement.
            defaultNames.push(name);
            try {
                init = assignmentExpression(!isStatement);
            } finally {
                defaultNames.pop();
            }
        } else if (varType == CONST) {
            throw error(AbstractParser.message("missing.const.assignment", name.getName()));
        }

        // Allocate var node.
        final VarNode var = new VarNode(varLine, varToken, finish, name.setIsDeclaredHere(), init, varFlags);
        vars.add(var);
        appendStatement(var);

        if (type != COMMARIGHT) {
            break;
        }
        next();
    }

    // If is a statement then handle end of line.
    if (isStatement) {
        final boolean semicolon = type == SEMICOLON;
        endOfLine();
        if (semicolon) {
            lc.getCurrentBlock().setFinish(finish);
        }
    }

    return vars;
}