11/*
2- * Copyright (c) 2017, 2018 , Oracle and/or its affiliates.
2+ * Copyright (c) 2017, 2019 , Oracle and/or its affiliates.
33 * Copyright (c) 2013, Regents of the University of California
44 *
55 * All rights reserved.
@@ -228,31 +228,31 @@ private SourceSection deriveSourceSection(RuleNode node) {
228228
229229 @ Override
230230 public Object visitFile_input (Python3Parser .File_inputContext ctx ) {
231- environment .enterScope (ctx .scope );
231+ environment .pushScope (ctx .scope );
232232 ExpressionNode file = asExpression (super .visitFile_input (ctx ));
233233 deriveSourceSection (ctx , file );
234- environment .leaveScope ();
234+ environment .popScope ();
235235 return factory .createModuleRoot (name , file , ctx .scope .getFrameDescriptor ());
236236 }
237237
238238 @ Override
239239 public Object visitEval_input (Python3Parser .Eval_inputContext ctx ) {
240- environment .enterScope (ctx .scope );
240+ environment .pushScope (ctx .scope );
241241 ExpressionNode node = (ExpressionNode ) super .visitEval_input (ctx );
242242 deriveSourceSection (ctx , node );
243243 StatementNode evalReturn = factory .createFrameReturn (factory .createWriteLocal (node , environment .getReturnSlot ()));
244244 ReturnTargetNode returnTarget = new ReturnTargetNode (evalReturn , factory .createReadLocal (environment .getReturnSlot ()));
245245 FunctionRootNode functionRoot = factory .createFunctionRoot (node .getSourceSection (), name , false , ctx .scope .getFrameDescriptor (), returnTarget , environment .getExecutionCellSlots ());
246- environment .leaveScope ();
246+ environment .popScope ();
247247 return functionRoot ;
248248 }
249249
250250 @ Override
251251 public Object visitSingle_input (Python3Parser .Single_inputContext ctx ) {
252- environment .enterScope (ctx .scope );
252+ environment .pushScope (ctx .scope );
253253 ExpressionNode body = asExpression (super .visitSingle_input (ctx ));
254254 deriveSourceSection (ctx , body );
255- environment .leaveScope ();
255+ environment .popScope ();
256256 if (isInlineMode ) {
257257 return body ;
258258 } else {
@@ -468,7 +468,7 @@ private ExpressionNode createComprehensionExpression(ParserRuleContext ctx, Pyth
468468
469469 private ExpressionNode createComprehensionExpression (ParserRuleContext ctx , Python3Parser .Comp_forContext compctx , Function <ParserRuleContext , ExpressionNode > getBlock ) {
470470 try {
471- environment .enterScope (compctx .scope );
471+ environment .pushScope (compctx .scope );
472472 ExpressionNode block = getBlock .apply (ctx );
473473 ExpressionNode yield = factory .createYield (block , environment .getReturnSlot ());
474474 yield .assignSourceSection (block .getSourceSection ());
@@ -482,13 +482,13 @@ private ExpressionNode createComprehensionExpression(ParserRuleContext ctx, Pyth
482482 genExprDef .assignSourceSection (srcSection );
483483 return genExprDef ;
484484 } finally {
485- environment .leaveScope ();
485+ environment .popScope ();
486486 }
487487 }
488488
489489 private GeneratorExpressionNode createGeneratorExpressionDefinition (ExpressionNode body , int lineNum ) {
490490 FrameDescriptor fd = environment .getCurrentFrame ();
491- String generatorName = source .getName () + ":generator_exp :" + lineNum ;
491+ String generatorName = environment . getCurrentScope (). getParent (). getScopeId () + ".<locals>.<genexp>:" + source .getName () + ":" + lineNum ;
492492 FunctionRootNode funcRoot = factory .createFunctionRoot (body .getSourceSection (), generatorName , true , fd , body , environment .getExecutionCellSlots ());
493493 GeneratorTranslator gtran = new GeneratorTranslator (funcRoot , true );
494494 RootCallTarget callTarget = gtran .translate ();
@@ -1440,7 +1440,7 @@ public Object visitFuncdef(Python3Parser.FuncdefContext ctx) {
14401440 }
14411441 }
14421442
1443- environment .enterScope (ctx .scope );
1443+ environment .pushScope (ctx .scope );
14441444 environment .setDefaultArgumentNodes (defaultArgs );
14451445
14461446 /**
@@ -1491,7 +1491,7 @@ public Object visitFuncdef(Python3Parser.FuncdefContext ctx) {
14911491 } else {
14921492 funcDef = new FunctionDefinitionNode (funcName , enclosingClassName , doc , arity , defaults , ct , environment .getDefinitionCellSlots (), environment .getExecutionCellSlots ());
14931493 }
1494- environment .leaveScope ();
1494+ environment .popScope ();
14951495
14961496 ReadNode funcVar = environment .findVariable (funcName );
14971497 return funcVar .makeWriteNode (funcDef );
@@ -1624,7 +1624,7 @@ private PNode createLambda(ParserRuleContext ctx, VarargslistContext varargslist
16241624 }
16251625
16261626 String funcname = "anonymous" ;
1627- environment .enterScope (scope );
1627+ environment .pushScope (scope );
16281628 environment .setDefaultArgumentNodes (defaultArgs );
16291629
16301630 /**
@@ -1667,7 +1667,7 @@ private PNode createLambda(ParserRuleContext ctx, VarargslistContext varargslist
16671667 } else {
16681668 funcDef = new FunctionDefinitionNode (funcname , null , null , arity , defaults , ct , environment .getDefinitionCellSlots (), environment .getExecutionCellSlots ());
16691669 }
1670- environment .leaveScope ();
1670+ environment .popScope ();
16711671
16721672 return funcDef ;
16731673 }
@@ -1730,14 +1730,14 @@ public Object visitClassdef(Python3Parser.ClassdefContext ctx) {
17301730 ExpressionNode [] splatArguments = new ExpressionNode [2 ];
17311731 visitCallArglist (ctx .arglist (), argumentNodes , keywords , splatArguments );
17321732
1733- environment .enterScope (ctx .scope );
1733+ environment .pushScope (ctx .scope );
17341734
17351735 ExpressionNode body = asClassBody (ctx .suite ().accept (this ), qualName );
17361736 ClassBodyRootNode classBodyRoot = factory .createClassBodyRoot (deriveSourceSection (ctx ), className , environment .getCurrentFrame (), body , environment .getExecutionCellSlots ());
17371737 RootCallTarget ct = Truffle .getRuntime ().createCallTarget (classBodyRoot );
17381738 FunctionDefinitionNode funcDef = new FunctionDefinitionNode (className , null , null , Arity .createOneArgumentWithVarKwArgs (className ),
17391739 factory .createBlock (), ct , environment .getDefinitionCellSlots (), environment .getExecutionCellSlots ());
1740- environment .leaveScope ();
1740+ environment .popScope ();
17411741
17421742 argumentNodes .add (0 , factory .createStringLiteral (className ));
17431743 argumentNodes .add (0 , funcDef );
@@ -1855,11 +1855,11 @@ private StatementNode createGeneratorExpression(Python3Parser.Comp_forContext co
18551855 // TODO: async
18561856 ScopeInfo old = null ;
18571857 if (iteratorInParentScope ) {
1858- old = environment .pushCurentScope ();
1858+ old = environment .popScope ();
18591859 }
18601860 ExpressionNode iterator = (ExpressionNode ) comp_for .or_test ().accept (this );
18611861 if (iteratorInParentScope ) {
1862- environment .popCurrentScope (old );
1862+ environment .pushScope (old );
18631863 }
18641864
18651865 StatementNode targets = assigns .translate (comp_for .exprlist ());
0 commit comments