< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/AssignSymbols.java

Print this page




 534         // Normally, a symbol assigned in a var statement is not live for its RHS. Since we also represent function
 535         // declarations as VarNodes, they are exception to the rule, as they need to have the symbol visible to the
 536         // body of the declared function for self-reference.
 537         if (varNode.isFunctionDeclaration()) {
 538             defineVarIdent(varNode);
 539         }
 540         return true;
 541     }
 542 
 543     @Override
 544     public Node leaveVarNode(final VarNode varNode) {
 545         if (!varNode.isFunctionDeclaration()) {
 546             defineVarIdent(varNode);
 547         }
 548         return super.leaveVarNode(varNode);
 549     }
 550 
 551     private void defineVarIdent(final VarNode varNode) {
 552         final IdentNode ident = varNode.getName();
 553         final int flags;
 554         if (varNode.isAnonymousFunctionDeclaration()) {
 555             flags = IS_INTERNAL;
 556         } else if (!varNode.isBlockScoped() && lc.getCurrentFunction().isProgram()) {
 557             flags = IS_SCOPE;
 558         } else {
 559             flags = 0;
 560         }
 561         defineSymbol(lc.getCurrentBlock(), ident.getName(), ident, varNode.getSymbolFlags() | flags);
 562     }
 563 
 564     private Symbol exceptionSymbol() {
 565         return newObjectInternal(EXCEPTION_PREFIX);
 566     }
 567 
 568     /**
 569      * This has to run before fix assignment types, store any type specializations for
 570      * parameters, then turn them into objects for the generic version of this method.
 571      *
 572      * @param functionNode functionNode
 573      */
 574     private FunctionNode finalizeParameters(final FunctionNode functionNode) {
 575         final List<IdentNode> newParams = new ArrayList<>();
 576         final boolean isVarArg = functionNode.isVarArg();




 534         // Normally, a symbol assigned in a var statement is not live for its RHS. Since we also represent function
 535         // declarations as VarNodes, they are exception to the rule, as they need to have the symbol visible to the
 536         // body of the declared function for self-reference.
 537         if (varNode.isFunctionDeclaration()) {
 538             defineVarIdent(varNode);
 539         }
 540         return true;
 541     }
 542 
 543     @Override
 544     public Node leaveVarNode(final VarNode varNode) {
 545         if (!varNode.isFunctionDeclaration()) {
 546             defineVarIdent(varNode);
 547         }
 548         return super.leaveVarNode(varNode);
 549     }
 550 
 551     private void defineVarIdent(final VarNode varNode) {
 552         final IdentNode ident = varNode.getName();
 553         final int flags;
 554         if (!varNode.isBlockScoped() && lc.getCurrentFunction().isProgram()) {


 555             flags = IS_SCOPE;
 556         } else {
 557             flags = 0;
 558         }
 559         defineSymbol(lc.getCurrentBlock(), ident.getName(), ident, varNode.getSymbolFlags() | flags);
 560     }
 561 
 562     private Symbol exceptionSymbol() {
 563         return newObjectInternal(EXCEPTION_PREFIX);
 564     }
 565 
 566     /**
 567      * This has to run before fix assignment types, store any type specializations for
 568      * parameters, then turn them into objects for the generic version of this method.
 569      *
 570      * @param functionNode functionNode
 571      */
 572     private FunctionNode finalizeParameters(final FunctionNode functionNode) {
 573         final List<IdentNode> newParams = new ArrayList<>();
 574         final boolean isVarArg = functionNode.isVarArg();


< prev index next >