nashorn/src/jdk/nashorn/internal/codegen/AssignSymbols.java
changeset 24759 31aed7d9c02a
parent 24751 ccbd9cd3f720
child 25238 28476bdc25ce
equal deleted inserted replaced
24758:eb9658fa0120 24759:31aed7d9c02a
   150         return functionNode;
   150         return functionNode;
   151     }
   151     }
   152 
   152 
   153     private final Deque<Set<String>> thisProperties = new ArrayDeque<>();
   153     private final Deque<Set<String>> thisProperties = new ArrayDeque<>();
   154     private final Map<String, Symbol> globalSymbols = new HashMap<>(); //reuse the same global symbol
   154     private final Map<String, Symbol> globalSymbols = new HashMap<>(); //reuse the same global symbol
   155     private final CompilationEnvironment env;
   155     private final Compiler compiler;
   156 
   156 
   157     public AssignSymbols(final CompilationEnvironment env) {
   157     public AssignSymbols(final Compiler compiler) {
   158         super(new LexicalContext());
   158         super(new LexicalContext());
   159         this.env   = env;
   159         this.compiler = compiler;
   160         this.log   = initLogger(env.getContext());
   160         this.log   = initLogger(compiler.getContext());
   161         this.debug = log.isEnabled();
   161         this.debug = log.isEnabled();
   162     }
   162     }
   163 
   163 
   164     @Override
   164     @Override
   165     public DebugLogger getLogger() {
   165     public DebugLogger getLogger() {
   214                 return varNode;
   214                 return varNode;
   215             }
   215             }
   216         });
   216         });
   217     }
   217     }
   218 
   218 
   219     private IdentNode compilerConstantIdentifier(CompilerConstants cc) {
   219     private IdentNode compilerConstantIdentifier(final CompilerConstants cc) {
   220         return (IdentNode)createImplicitIdentifier(cc.symbolName()).setSymbol(lc.getCurrentFunction().compilerConstant(cc));
   220         return (IdentNode)createImplicitIdentifier(cc.symbolName()).setSymbol(lc.getCurrentFunction().compilerConstant(cc));
   221     }
   221     }
   222 
   222 
   223     /**
   223     /**
   224      * Creates an ident node for an implicit identifier within the function (one not declared in the script source
   224      * Creates an ident node for an implicit identifier within the function (one not declared in the script source
   380             }
   380             }
   381         } else if (symbol.less(flags)) {
   381         } else if (symbol.less(flags)) {
   382             symbol.setFlags(flags);
   382             symbol.setFlags(flags);
   383         }
   383         }
   384 
   384 
   385         if((isVar || isParam) && env.useOptimisticTypes() && env.isOnDemandCompilation()) {
   385         if((isVar || isParam) && compiler.useOptimisticTypes() && compiler.isOnDemandCompilation()) {
   386             env.declareLocalSymbol(name);
   386             compiler.declareLocalSymbol(name);
   387         }
   387         }
   388 
   388 
   389         return symbol;
   389         return symbol;
   390     }
   390     }
   391 
   391 
   749 
   749 
   750         return end(forNode);
   750         return end(forNode);
   751     }
   751     }
   752 
   752 
   753     @Override
   753     @Override
   754     public Node leaveFunctionNode(FunctionNode functionNode) {
   754     public Node leaveFunctionNode(final FunctionNode functionNode) {
   755 
   755 
   756         return markProgramBlock(
   756         return markProgramBlock(
   757                removeUnusedSlots(
   757                removeUnusedSlots(
   758                createSyntheticInitializers(
   758                createSyntheticInitializers(
   759                finalizeParameters(
   759                finalizeParameters(
   840         end(unaryNode);
   840         end(unaryNode);
   841 
   841 
   842         return runtimeNode;
   842         return runtimeNode;
   843     }
   843     }
   844 
   844 
   845     private FunctionNode markProgramBlock(FunctionNode functionNode) {
   845     private FunctionNode markProgramBlock(final FunctionNode functionNode) {
   846         if (env.isOnDemandCompilation() || !functionNode.isProgram()) {
   846         if (compiler.isOnDemandCompilation() || !functionNode.isProgram()) {
   847             return functionNode;
   847             return functionNode;
   848         }
   848         }
   849 
   849 
   850         assert functionNode.getId() == 1;
   850         assert functionNode.getId() == 1;
   851         return functionNode.setBody(lc, functionNode.getBody().setFlag(lc, Block.IS_GLOBAL_SCOPE));
   851         return functionNode.setBody(lc, functionNode.getBody().setFlag(lc, Block.IS_GLOBAL_SCOPE));