1
1
/*
2
- * Copyright (c) 2017, 2018 , Oracle and/or its affiliates.
2
+ * Copyright (c) 2017, 2019 , Oracle and/or its affiliates.
3
3
* Copyright (c) 2013, Regents of the University of California
4
4
*
5
5
* All rights reserved.
@@ -228,31 +228,31 @@ private SourceSection deriveSourceSection(RuleNode node) {
228
228
229
229
@ Override
230
230
public Object visitFile_input (Python3Parser .File_inputContext ctx ) {
231
- environment .enterScope (ctx .scope );
231
+ environment .pushScope (ctx .scope );
232
232
ExpressionNode file = asExpression (super .visitFile_input (ctx ));
233
233
deriveSourceSection (ctx , file );
234
- environment .leaveScope ();
234
+ environment .popScope ();
235
235
return factory .createModuleRoot (name , file , ctx .scope .getFrameDescriptor ());
236
236
}
237
237
238
238
@ Override
239
239
public Object visitEval_input (Python3Parser .Eval_inputContext ctx ) {
240
- environment .enterScope (ctx .scope );
240
+ environment .pushScope (ctx .scope );
241
241
ExpressionNode node = (ExpressionNode ) super .visitEval_input (ctx );
242
242
deriveSourceSection (ctx , node );
243
243
StatementNode evalReturn = factory .createFrameReturn (factory .createWriteLocal (node , environment .getReturnSlot ()));
244
244
ReturnTargetNode returnTarget = new ReturnTargetNode (evalReturn , factory .createReadLocal (environment .getReturnSlot ()));
245
245
FunctionRootNode functionRoot = factory .createFunctionRoot (node .getSourceSection (), name , false , ctx .scope .getFrameDescriptor (), returnTarget , environment .getExecutionCellSlots ());
246
- environment .leaveScope ();
246
+ environment .popScope ();
247
247
return functionRoot ;
248
248
}
249
249
250
250
@ Override
251
251
public Object visitSingle_input (Python3Parser .Single_inputContext ctx ) {
252
- environment .enterScope (ctx .scope );
252
+ environment .pushScope (ctx .scope );
253
253
ExpressionNode body = asExpression (super .visitSingle_input (ctx ));
254
254
deriveSourceSection (ctx , body );
255
- environment .leaveScope ();
255
+ environment .popScope ();
256
256
if (isInlineMode ) {
257
257
return body ;
258
258
} else {
@@ -468,7 +468,7 @@ private ExpressionNode createComprehensionExpression(ParserRuleContext ctx, Pyth
468
468
469
469
private ExpressionNode createComprehensionExpression (ParserRuleContext ctx , Python3Parser .Comp_forContext compctx , Function <ParserRuleContext , ExpressionNode > getBlock ) {
470
470
try {
471
- environment .enterScope (compctx .scope );
471
+ environment .pushScope (compctx .scope );
472
472
ExpressionNode block = getBlock .apply (ctx );
473
473
ExpressionNode yield = factory .createYield (block , environment .getReturnSlot ());
474
474
yield .assignSourceSection (block .getSourceSection ());
@@ -482,13 +482,13 @@ private ExpressionNode createComprehensionExpression(ParserRuleContext ctx, Pyth
482
482
genExprDef .assignSourceSection (srcSection );
483
483
return genExprDef ;
484
484
} finally {
485
- environment .leaveScope ();
485
+ environment .popScope ();
486
486
}
487
487
}
488
488
489
489
private GeneratorExpressionNode createGeneratorExpressionDefinition (ExpressionNode body , int lineNum ) {
490
490
FrameDescriptor fd = environment .getCurrentFrame ();
491
- String generatorName = source .getName () + ":generator_exp :" + lineNum ;
491
+ String generatorName = environment . getCurrentScope (). getParent (). getScopeId () + ".<locals>.<genexp>:" + source .getName () + ":" + lineNum ;
492
492
FunctionRootNode funcRoot = factory .createFunctionRoot (body .getSourceSection (), generatorName , true , fd , body , environment .getExecutionCellSlots ());
493
493
GeneratorTranslator gtran = new GeneratorTranslator (funcRoot , true );
494
494
RootCallTarget callTarget = gtran .translate ();
@@ -1440,7 +1440,7 @@ public Object visitFuncdef(Python3Parser.FuncdefContext ctx) {
1440
1440
}
1441
1441
}
1442
1442
1443
- environment .enterScope (ctx .scope );
1443
+ environment .pushScope (ctx .scope );
1444
1444
environment .setDefaultArgumentNodes (defaultArgs );
1445
1445
1446
1446
/**
@@ -1491,7 +1491,7 @@ public Object visitFuncdef(Python3Parser.FuncdefContext ctx) {
1491
1491
} else {
1492
1492
funcDef = new FunctionDefinitionNode (funcName , enclosingClassName , doc , arity , defaults , ct , environment .getDefinitionCellSlots (), environment .getExecutionCellSlots ());
1493
1493
}
1494
- environment .leaveScope ();
1494
+ environment .popScope ();
1495
1495
1496
1496
ReadNode funcVar = environment .findVariable (funcName );
1497
1497
return funcVar .makeWriteNode (funcDef );
@@ -1624,7 +1624,7 @@ private PNode createLambda(ParserRuleContext ctx, VarargslistContext varargslist
1624
1624
}
1625
1625
1626
1626
String funcname = "anonymous" ;
1627
- environment .enterScope (scope );
1627
+ environment .pushScope (scope );
1628
1628
environment .setDefaultArgumentNodes (defaultArgs );
1629
1629
1630
1630
/**
@@ -1667,7 +1667,7 @@ private PNode createLambda(ParserRuleContext ctx, VarargslistContext varargslist
1667
1667
} else {
1668
1668
funcDef = new FunctionDefinitionNode (funcname , null , null , arity , defaults , ct , environment .getDefinitionCellSlots (), environment .getExecutionCellSlots ());
1669
1669
}
1670
- environment .leaveScope ();
1670
+ environment .popScope ();
1671
1671
1672
1672
return funcDef ;
1673
1673
}
@@ -1730,14 +1730,14 @@ public Object visitClassdef(Python3Parser.ClassdefContext ctx) {
1730
1730
ExpressionNode [] splatArguments = new ExpressionNode [2 ];
1731
1731
visitCallArglist (ctx .arglist (), argumentNodes , keywords , splatArguments );
1732
1732
1733
- environment .enterScope (ctx .scope );
1733
+ environment .pushScope (ctx .scope );
1734
1734
1735
1735
ExpressionNode body = asClassBody (ctx .suite ().accept (this ), qualName );
1736
1736
ClassBodyRootNode classBodyRoot = factory .createClassBodyRoot (deriveSourceSection (ctx ), className , environment .getCurrentFrame (), body , environment .getExecutionCellSlots ());
1737
1737
RootCallTarget ct = Truffle .getRuntime ().createCallTarget (classBodyRoot );
1738
1738
FunctionDefinitionNode funcDef = new FunctionDefinitionNode (className , null , null , Arity .createOneArgumentWithVarKwArgs (className ),
1739
1739
factory .createBlock (), ct , environment .getDefinitionCellSlots (), environment .getExecutionCellSlots ());
1740
- environment .leaveScope ();
1740
+ environment .popScope ();
1741
1741
1742
1742
argumentNodes .add (0 , factory .createStringLiteral (className ));
1743
1743
argumentNodes .add (0 , funcDef );
@@ -1855,11 +1855,11 @@ private StatementNode createGeneratorExpression(Python3Parser.Comp_forContext co
1855
1855
// TODO: async
1856
1856
ScopeInfo old = null ;
1857
1857
if (iteratorInParentScope ) {
1858
- old = environment .pushCurentScope ();
1858
+ old = environment .popScope ();
1859
1859
}
1860
1860
ExpressionNode iterator = (ExpressionNode ) comp_for .or_test ().accept (this );
1861
1861
if (iteratorInParentScope ) {
1862
- environment .popCurrentScope (old );
1862
+ environment .pushScope (old );
1863
1863
}
1864
1864
1865
1865
StatementNode targets = assigns .translate (comp_for .exprlist ());
0 commit comments