@@ -156,6 +156,8 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
156
156
// Parse to the YARP AST
157
157
final RubyDeferredWarnings rubyWarnings = new RubyDeferredWarnings ();
158
158
159
+ final String sourcePath = rubySource .getSourcePath (language ).intern ();
160
+
159
161
// Only use the cache while loading top-level core library files, as eval() later could use
160
162
// the same Source name but should not use the cache. For instance,
161
163
// TOPLEVEL_BINDING.eval("self") would use the cache which is wrong.
@@ -168,12 +170,12 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
168
170
parseResult = context .getMetricsProfiler ().callWithMetrics (
169
171
"parsing" ,
170
172
source .getName (),
171
- () -> parseToYARPAST (language , rubySource , localsInScopes ,
172
- parseEnvironment ));
173
+ () -> parseToYARPAST (rubySource , sourcePath , yarpSource , localsInScopes ,
174
+ language . options . FROZEN_STRING_LITERALS ));
173
175
printParseTranslateExecuteMetric ("after-parsing" , context , source );
174
176
}
175
177
176
- handleWarningsErrorsPrimitives (context , language , parseResult , rubySource , parseEnvironment , rubyWarnings );
178
+ handleWarningsErrorsPrimitives (context , parseResult , rubySource , sourcePath , parseEnvironment , rubyWarnings );
177
179
178
180
var node = parseResult .value ;
179
181
@@ -355,18 +357,14 @@ private String getMethodName(ParserContext parserContext, MaterializedFrame pare
355
357
}
356
358
}
357
359
358
- public static ParseResult parseToYARPAST (RubyLanguage language , RubySource rubySource ,
359
- List <List <String >> localsInScopes , ParseEnvironment parseEnvironment ) {
360
+ public static ParseResult parseToYARPAST (RubySource rubySource , String sourcePath , Nodes . Source yarpSource ,
361
+ List <List <String >> localsInScopes , boolean frozenStringLiteral ) {
360
362
TruffleSafepoint .poll (DummyNode .INSTANCE );
361
363
362
- // intern() to improve footprint
363
- String sourcePath = rubySource .getSourcePath (language ).intern ();
364
-
365
364
byte [] sourceBytes = rubySource .getBytes ();
366
365
final byte [] filepath = sourcePath .getBytes (Encodings .FILESYSTEM_CHARSET );
367
366
int line = rubySource .getLineOffset () + 1 ;
368
367
byte [] encoding = StringOperations .encodeAsciiBytes (rubySource .getEncoding ().toString ()); // encoding name is supposed to contain only ASCII characters
369
- boolean frozenStringLiteral = language .options .FROZEN_STRING_LITERALS ;
370
368
var version = ParsingOptions .SyntaxVersion .V3_3_0 ;
371
369
372
370
byte [][][] scopes ;
@@ -400,17 +398,13 @@ public static ParseResult parseToYARPAST(RubyLanguage language, RubySource rubyS
400
398
scopes );
401
399
byte [] serializedBytes = Parser .parseAndSerialize (sourceBytes , parsingOptions );
402
400
403
- Nodes .Source yarpSource = parseEnvironment .yarpSource ;
404
401
return YARPLoader .load (serializedBytes , yarpSource , rubySource );
405
402
}
406
403
407
- public static void handleWarningsErrorsPrimitives (RubyContext context , RubyLanguage language ,
408
- ParseResult parseResult , RubySource rubySource , ParseEnvironment parseEnvironment ,
404
+ public static void handleWarningsErrorsPrimitives (RubyContext context , ParseResult parseResult ,
405
+ RubySource rubySource , String sourcePath , ParseEnvironment parseEnvironment ,
409
406
RubyDeferredWarnings rubyWarnings ) {
410
407
411
- // intern() to improve footprint
412
- String sourcePath = rubySource .getSourcePath (language ).intern ();
413
-
414
408
final ParseResult .Error [] errors = parseResult .errors ;
415
409
416
410
// collect warnings generated by the parser
@@ -464,25 +458,20 @@ public static void handleWarningsErrorsPrimitives(RubyContext context, RubyLangu
464
458
parseEnvironment .allowTruffleRubyPrimitives = allowTruffleRubyPrimitives ;
465
459
}
466
460
467
- public static void handleWarningsErrorsNoContext (RubyLanguage language , ParseResult parseResult ,
468
- RubySource rubySource , Nodes .Source yarpSource ) {
461
+ public static void handleWarningsErrorsNoContext (ParseResult parseResult , String sourcePath ,
462
+ Nodes .Source yarpSource ) {
469
463
if (parseResult .errors .length > 0 ) {
470
464
var error = parseResult .errors [0 ];
471
465
throw CompilerDirectives .shouldNotReachHere ("Parse error in " +
472
- fileLineYARPSource ( error . location , language , rubySource , yarpSource ) + ": " + error .message );
466
+ sourcePath + ":" + yarpSource . line ( error . location . startOffset ) + ": " + error .message );
473
467
}
474
468
475
469
for (var warning : parseResult .warnings ) {
476
470
throw CompilerDirectives .shouldNotReachHere ("Warning in " +
477
- fileLineYARPSource ( warning . location , language , rubySource , yarpSource ) + ": " + warning .message );
471
+ sourcePath + ":" + yarpSource . line ( warning . location . startOffset ) + ": " + warning .message );
478
472
}
479
473
}
480
474
481
- private static String fileLineYARPSource (Nodes .Location location , RubyLanguage language , RubySource rubySource ,
482
- Nodes .Source yarpSource ) {
483
- return rubySource .getSourcePath (language ) + ":" + yarpSource .line (location .startOffset );
484
- }
485
-
486
475
public static Nodes .Source createYARPSource (byte [] sourceBytes ) {
487
476
return new Nodes .Source (sourceBytes );
488
477
}
0 commit comments