Skip to content

Commit 3283b64

Browse files
committed
Remove verboisty checks and context from ParserSupport
1 parent 20ffdb1 commit 3283b64

File tree

5 files changed

+26
-49
lines changed

5 files changed

+26
-49
lines changed

src/main/java/org/truffleruby/parser/TranslatorDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public static RootParseNode parseToJRubyAST(RubyContext context, RubySource ruby
411411
configuration.parseAsBlock(blockScope);
412412
}
413413

414-
RubyParser parser = new RubyParser(context, lexerSource, rubyWarnings);
414+
RubyParser parser = new RubyParser(lexerSource, rubyWarnings);
415415
RubyParserResult result;
416416
try {
417417
result = parser.parse(configuration);

src/main/java/org/truffleruby/parser/lexer/RubyLexer.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public void updateLineOffset() {
403403

404404
protected void setCompileOptionFlag(String name, Rope value) {
405405
if (tokenSeen) {
406-
warnings.warn(
406+
warnings.warning(
407407
getFile(),
408408
getPosition().toSourceSection(src.getSource()).getStartLine(),
409409
"`" + name + "' is ignored after any tokens");
@@ -851,15 +851,10 @@ private int yylex() {
851851
case '#': { /* it's a comment */
852852
this.tokenSeen = tokenSeen;
853853

854-
// There are no magic comments that can affect any runtime options after a token has been seen, so there's
855-
// no point in looking for them. However, if warnings are enabled, we do need to scan for the magic comment
856-
// so we can report that it will be ignored.
857-
if (!tokenSeen || (parserSupport.getContext() != null &&
858-
parserSupport.getContext().getCoreLibrary().isVerbose())) {
859-
if (!parser_magic_comment(lexb, lex_p, lex_pend - lex_p, parserRopeOperations, this)) {
860-
if (comment_at_top()) {
861-
set_file_encoding(lex_p, lex_pend);
862-
}
854+
// Always scan for magic comments, verbosity is not known at this time.
855+
if (!parser_magic_comment(lexb, lex_p, lex_pend - lex_p, parserRopeOperations, this)) {
856+
if (comment_at_top()) {
857+
set_file_encoding(lex_p, lex_pend);
863858
}
864859
}
865860

src/main/java/org/truffleruby/parser/parser/ParserSupport.java

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import org.jcodings.specific.SJISEncoding;
4848
import org.jcodings.specific.USASCIIEncoding;
4949
import org.jcodings.specific.UTF8Encoding;
50-
import org.truffleruby.RubyContext;
50+
import org.truffleruby.RubyLanguage;
5151
import org.truffleruby.SuppressFBWarnings;
5252
import org.truffleruby.core.encoding.EncodingManager;
5353
import org.truffleruby.core.regexp.ClassicRegexp;
@@ -176,21 +176,15 @@ private static String prefixName(String name) {
176176
protected ParserConfiguration configuration;
177177
private RubyParserResult result;
178178

179-
private final RubyContext context;
180179
private final String file;
181180
private final RubyDeferredWarnings warnings;
182181
private final ParserRopeOperations parserRopeOperations = new ParserRopeOperations();
183182

184-
public ParserSupport(RubyContext context, LexerSource source, RubyDeferredWarnings warnings) {
185-
this.context = context;
183+
public ParserSupport(LexerSource source, RubyDeferredWarnings warnings) {
186184
this.file = source.getSourcePath();
187185
this.warnings = warnings;
188186
}
189187

190-
public RubyContext getContext() {
191-
return context;
192-
}
193-
194188
public void reset() {
195189
inSingleton = 0;
196190
inDefinition = false;
@@ -408,7 +402,7 @@ public ParseNode appendToBlock(ParseNode head, ParseNode tail) {
408402
head = new BlockParseNode(head.getPosition()).add(head);
409403
}
410404

411-
if (isVerbose() && isBreakStatement(((ListParseNode) head).getLast())) {
405+
if (isBreakStatement(((ListParseNode) head).getLast())) {
412406
warnings.warning(
413407
file,
414408
tail.getPosition().toSourceSection(lexer.getSource()).getStartLine(),
@@ -420,14 +414,6 @@ public ParseNode appendToBlock(ParseNode head, ParseNode tail) {
420414
return head;
421415
}
422416

423-
private boolean isVerbose() {
424-
return context != null && context.getCoreLibrary().isVerbose();
425-
}
426-
427-
private boolean warningsEnabled() {
428-
return context.getCoreLibrary().warningsEnabled();
429-
}
430-
431417
// We know it has to be tLABEL or tIDENTIFIER so none of the other assignable logic is needed
432418
public AssignableParseNode assignableInCurr(Rope name, ParseNode value) {
433419
String nameString = name.getString().intern();
@@ -640,7 +626,7 @@ public boolean checkExpression(ParseNode node) {
640626
}
641627

642628
private void handleUselessWarn(ParseNode node, String useless) {
643-
warnings.warn(
629+
warnings.warning(
644630
file,
645631
node.getPosition().toSourceSection(lexer.getSource()).getStartLine(),
646632
"Useless use of " + useless + " in void context.");
@@ -650,7 +636,7 @@ private void handleUselessWarn(ParseNode node, String useless) {
650636
*
651637
* @param node to be checked. */
652638
public void checkUselessStatement(ParseNode node) {
653-
if (!isVerbose() || (!configuration.isInlineSource() && configuration.isEvalParse())) {
639+
if (!configuration.isInlineSource() && configuration.isEvalParse()) {
654640
return;
655641
}
656642

@@ -736,15 +722,13 @@ public void checkUselessStatement(ParseNode node) {
736722
*
737723
* @param blockNode to be checked. */
738724
public void checkUselessStatements(BlockParseNode blockNode) {
739-
if (isVerbose()) {
740-
ParseNode lastNode = blockNode.getLast();
725+
ParseNode lastNode = blockNode.getLast();
741726

742-
for (int i = 0; i < blockNode.size(); i++) {
743-
ParseNode currentNode = blockNode.get(i);
727+
for (int i = 0; i < blockNode.size(); i++) {
728+
ParseNode currentNode = blockNode.get(i);
744729

745-
if (lastNode != currentNode) {
746-
checkUselessStatement(currentNode);
747-
}
730+
if (lastNode != currentNode) {
731+
checkUselessStatement(currentNode);
748732
}
749733
}
750734
}
@@ -1271,7 +1255,7 @@ public ParseNode asSymbol(SourceIndexLength position, ParseNode value) {
12711255
private void checkSymbolCodeRange(SymbolParseNode symbolParseNode) {
12721256
if (symbolParseNode.getRope().getCodeRange() == CR_BROKEN) {
12731257
throw new RaiseException(
1274-
getContext(),
1258+
RubyLanguage.getCurrentContext(),
12751259
getConfiguration().getContext().getCoreExceptions().encodingError("invalid encoding symbol", null));
12761260
}
12771261
}
@@ -1703,7 +1687,7 @@ private void allocateNamedLocals(RegexpParseNode regexpNode) {
17031687
int slot = scope.isDefined(names[i]);
17041688
if (slot >= 0) {
17051689
// If verbose and the variable is not just another named capture, warn
1706-
if (isVerbose() && !scope.isNamedCapture(slot)) {
1690+
if (!scope.isNamedCapture(slot)) {
17071691
warn(getPosition(regexpNode), "named capture conflicts a local variable - " + names[i]);
17081692
}
17091693
} else {
@@ -1746,7 +1730,7 @@ public RuntimeException compile_error(String message) { // mri: rb_compile_error
17461730
}
17471731

17481732
throw new RaiseException(
1749-
getContext(),
1733+
RubyLanguage.getCurrentContext(),
17501734
getConfiguration().getContext().getCoreExceptions().syntaxError(
17511735
errorMessage + message,
17521736
null,

src/main/java/org/truffleruby/parser/parser/RubyParser.java

Lines changed: 5 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/org/truffleruby/parser/parser/RubyParser.y

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package org.truffleruby.parser.parser;
33

44
import org.jcodings.Encoding;
55
import org.jcodings.specific.UTF8Encoding;
6-
import org.truffleruby.RubyContext;
76
import org.truffleruby.SuppressFBWarnings;
87
import org.truffleruby.core.rope.CodeRange;
98
import org.truffleruby.core.rope.Rope;
@@ -115,8 +114,8 @@ public class RubyParser {
115114
protected final ParserSupport support;
116115
protected final RubyLexer lexer;
117116

118-
public RubyParser(RubyContext context, LexerSource source, RubyDeferredWarnings warnings) {
119-
this.support = new ParserSupport(context, source, warnings);
117+
public RubyParser(LexerSource source, RubyDeferredWarnings warnings) {
118+
this.support = new ParserSupport(source, warnings);
120119
this.lexer = new RubyLexer(support, source, warnings);
121120
support.setLexer(lexer);
122121
}

0 commit comments

Comments
 (0)