@@ -123,7 +123,7 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
123
123
* we look them up ourselves after being told they're in some parent scope. */
124
124
125
125
final TranslatorEnvironment parentEnvironment ;
126
- final List <List <String >> localVariableNames = new ArrayList <>();
126
+ final List <List <String >> localsInScopes = new ArrayList <>();
127
127
128
128
int blockDepth = 0 ;
129
129
if (parentFrame != null ) {
@@ -139,7 +139,7 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
139
139
}
140
140
}
141
141
142
- localVariableNames .add (names );
142
+ localsInScopes .add (names );
143
143
frame = RubyArguments .getDeclarationFrame (frame );
144
144
blockDepth ++;
145
145
}
@@ -150,7 +150,7 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
150
150
}
151
151
152
152
if (argumentNames != null ) {
153
- // TODO: add these variables and treat it more like an eval case
153
+ localsInScopes . add ( Arrays . asList ( argumentNames ));
154
154
}
155
155
156
156
// Parse to the YARP AST
@@ -168,7 +168,7 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
168
168
parseResult = context .getMetricsProfiler ().callWithMetrics (
169
169
"parsing" ,
170
170
source .getName (),
171
- () -> parseToYARPAST (language , rubySource , localVariableNames ,
171
+ () -> parseToYARPAST (language , rubySource , localsInScopes ,
172
172
parseEnvironment ));
173
173
printParseTranslateExecuteMetric ("after-parsing" , context , source );
174
174
}
@@ -356,25 +356,23 @@ private String getMethodName(ParserContext parserContext, MaterializedFrame pare
356
356
}
357
357
358
358
public static ParseResult parseToYARPAST (RubyLanguage language , RubySource rubySource ,
359
- List <List <String >> localVariableNames , ParseEnvironment parseEnvironment ) {
359
+ List <List <String >> localsInScopes , ParseEnvironment parseEnvironment ) {
360
360
TruffleSafepoint .poll (DummyNode .INSTANCE );
361
361
362
- byte [] sourceBytes = rubySource .getBytes ();
362
+ // intern() to improve footprint
363
+ String sourcePath = rubySource .getSourcePath (language ).intern ();
363
364
364
- byte [] filepath ;
365
+ byte [] sourceBytes = rubySource .getBytes ();
366
+ final byte [] filepath = sourcePath .getBytes (Encodings .FILESYSTEM_CHARSET );
365
367
int line = rubySource .getLineOffset () + 1 ;
366
368
byte [] encoding = StringOperations .encodeAsciiBytes (rubySource .getEncoding ().toString ()); // encoding name is supposed to contain only ASCII characters
367
369
boolean frozenStringLiteral = language .options .FROZEN_STRING_LITERALS ;
368
370
var version = ParsingOptions .SyntaxVersion .V3_3_0 ;
369
- byte [][][] scopes ;
370
371
371
- // intern() to improve footprint
372
- String sourcePath = rubySource .getSourcePath (language ).intern ();
373
-
374
- if (rubySource .isEval ()) {
375
- filepath = sourcePath .getBytes (Encodings .FILESYSTEM_CHARSET );
372
+ byte [][][] scopes ;
376
373
377
- int scopesCount = localVariableNames .size ();
374
+ if (!localsInScopes .isEmpty ()) {
375
+ int scopesCount = localsInScopes .size ();
378
376
// Add one empty extra scope at the end to have local variables treated by Prism
379
377
// as declared in the outer scope.
380
378
// See https://github.com/ruby/prism/issues/2327 and https://github.com/ruby/prism/issues/2192
@@ -383,7 +381,7 @@ public static ParseResult parseToYARPAST(RubyLanguage language, RubySource rubyS
383
381
for (int i = 0 ; i < scopesCount ; i ++) {
384
382
// Local variables are in order from inner scope to outer one, but Prism expects order from outer to inner.
385
383
// So we need to reverse the order
386
- var namesList = localVariableNames .get (scopesCount - 1 - i );
384
+ var namesList = localsInScopes .get (scopesCount - 1 - i );
387
385
byte [][] namesBytes = new byte [namesList .size ()][];
388
386
int j = 0 ;
389
387
for (var name : namesList ) {
@@ -395,9 +393,6 @@ public static ParseResult parseToYARPAST(RubyLanguage language, RubySource rubyS
395
393
396
394
scopes [scopes .length - 1 ] = new byte [][]{};
397
395
} else {
398
- assert localVariableNames .isEmpty (); // parsing of the whole source file cannot have outer scopes
399
-
400
- filepath = sourcePath .getBytes (Encodings .FILESYSTEM_CHARSET );
401
396
scopes = new byte [0 ][][];
402
397
}
403
398
0 commit comments