Skip to content

Commit

Permalink
[GR-15990] Remove RubyContext from Translator
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/2519
  • Loading branch information
bjfish committed Mar 23, 2021
2 parents 684846d + af863fc commit 169bce9
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 25 deletions.
15 changes: 9 additions & 6 deletions src/main/java/org/truffleruby/parser/BodyTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ public class BodyTranslator extends Translator {
protected String currentCallMethodName = null;

public BodyTranslator(
RubyContext context,
RubyLanguage language,
BodyTranslator parent,
TranslatorEnvironment environment,
Source source,
ParserContext parserContext,
Node currentNode,
RubyDeferredWarnings rubyWarnings) {
super(context, source, parserContext, currentNode);
super(language, source, parserContext, currentNode);
this.parent = parent;
this.environment = environment;
this.rubyWarnings = rubyWarnings;
Expand Down Expand Up @@ -1032,7 +1032,7 @@ private RubyNode openModule(SourceIndexLength sourceSection, RubyNode defineOrGe
modulePath);

final BodyTranslator moduleTranslator = new BodyTranslator(
context,
language,
this,
newEnvironment,
source,
Expand Down Expand Up @@ -1482,7 +1482,7 @@ protected RubyNode translateMethodDefinition(SourceIndexLength sourceSection, Ru
// ownScopeForAssignments is the same for the defined method as the current one.

final MethodTranslator methodCompiler = new MethodTranslator(
context,
language,
this,
newEnvironment,
false,
Expand Down Expand Up @@ -1997,7 +1997,7 @@ private RubyNode translateBlockLikeNode(IterParseNode node, boolean isLambda) {
TranslatorEnvironment.newFrameDescriptor(),
environment.modulePath);
final MethodTranslator methodCompiler = new MethodTranslator(
context,
language,
this,
newEnvironment,
true,
Expand Down Expand Up @@ -3097,7 +3097,10 @@ private RubyNode addNewlineIfNeeded(ParseNode jrubyNode, RubyNode node) {

if (environment.getParseEnvironment().isCoverageEnabled()) {
node.unsafeSetIsCoverageLine();
context.getCoverageManager().setLineHasCode(source, current.toSourceSection(source).getStartLine());
environment.getParseEnvironment().contextIfSingleContext
.get()
.getCoverageManager()
.setLineHasCode(source, current.toSourceSection(source).getStartLine());
}
node.unsafeSetIsNewLine();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.List;

import com.oracle.truffle.api.frame.FrameSlotKind;
import org.truffleruby.RubyContext;
import org.truffleruby.RubyLanguage;
import org.truffleruby.core.IsNilNode;
import org.truffleruby.core.array.ArrayIndexNodes;
import org.truffleruby.core.array.ArrayLiteralNode;
Expand Down Expand Up @@ -109,13 +109,13 @@ private enum State {
public LoadArgumentsTranslator(
Node currentNode,
ArgsParseNode argsNode,
RubyContext context,
RubyLanguage language,
Source source,
ParserContext parserContext,
boolean isProc,
boolean isMethod,
BodyTranslator methodBodyTranslator) {
super(context, source, parserContext, currentNode);
super(language, source, parserContext, currentNode);
this.isProc = isProc;
this.isMethod = isMethod;
this.methodBodyTranslator = methodBodyTranslator;
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/org/truffleruby/parser/MethodTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.Arrays;
import java.util.function.Supplier;

import org.truffleruby.RubyContext;
import org.truffleruby.RubyLanguage;
import org.truffleruby.collections.CachedSupplier;
import org.truffleruby.core.IsNilNode;
Expand Down Expand Up @@ -76,7 +75,7 @@ public class MethodTranslator extends BodyTranslator {
private final String methodNameForBlock;

public MethodTranslator(
RubyContext context,
RubyLanguage language,
BodyTranslator parent,
TranslatorEnvironment environment,
boolean isBlock,
Expand All @@ -86,7 +85,7 @@ public MethodTranslator(
ArgsParseNode argsNode,
String methodNameForBlock,
RubyDeferredWarnings rubyWarnings) {
super(context, parent, environment, source, parserContext, currentNode, rubyWarnings);
super(language, parent, environment, source, parserContext, currentNode, rubyWarnings);
this.isBlock = isBlock;
this.argsNode = argsNode;
this.methodNameForBlock = methodNameForBlock;
Expand Down Expand Up @@ -121,7 +120,7 @@ public BlockDefinitionNode compileBlockNode(SourceIndexLength sourceSection, Par
final RubyNode loadArguments = new LoadArgumentsTranslator(
currentNode,
argsNode,
context,
language,
source,
parserContext,
!isStabbyLambda,
Expand Down Expand Up @@ -217,7 +216,7 @@ private RubyNode preludeProc(
final LoadArgumentsTranslator destructureArgumentsTranslator = new LoadArgumentsTranslator(
currentNode,
argsNode,
context,
language,
source,
parserContext,
!isStabbyLambda,
Expand Down Expand Up @@ -390,7 +389,7 @@ public RubyNode compileMethodBody(SourceIndexLength sourceSection, ParseNode bod
final RubyNode loadArguments = new LoadArgumentsTranslator(
currentNode,
argsNode,
context,
language,
source,
parserContext,
false,
Expand Down Expand Up @@ -504,7 +503,7 @@ public RubyNode visitZSuperNode(ZSuperParseNode node) {
}

final ReloadArgumentsTranslator reloadTranslator = new ReloadArgumentsTranslator(
context,
language,
source,
parserContext,
currentNode,
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/truffleruby/parser/ParseEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
*/
package org.truffleruby.parser;

import org.truffleruby.RubyContext;
import org.truffleruby.RubyLanguage;
import org.truffleruby.SuppressFBWarnings;
import org.truffleruby.language.LexicalScope;
import org.truffleruby.language.control.BreakID;
import org.truffleruby.language.control.ReturnID;

import java.util.Optional;

/** Translator environment, unique per parse/translation. */
public class ParseEnvironment {

Expand All @@ -23,10 +26,12 @@ public class ParseEnvironment {
public boolean allowTruffleRubyPrimitives = false;
private final String corePath;
private final boolean coverageEnabled;
public final Optional<RubyContext> contextIfSingleContext;

public ParseEnvironment(RubyLanguage language) {
corePath = language.corePath;
coverageEnabled = language.contextIfSingleContext.map(c -> c.getCoverageManager().isEnabled()).orElse(false);
contextIfSingleContext = language.contextIfSingleContext;
}

public String getCorePath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.ArrayList;
import java.util.List;

import org.truffleruby.RubyContext;
import org.truffleruby.RubyLanguage;
import org.truffleruby.core.hash.ConcatHashLiteralNode;
import org.truffleruby.core.hash.HashLiteralNode;
import org.truffleruby.language.RubyNode;
Expand Down Expand Up @@ -46,12 +46,12 @@ public class ReloadArgumentsTranslator extends Translator {
private int restParameterIndex = -1;

public ReloadArgumentsTranslator(
RubyContext context,
RubyLanguage language,
Source source,
ParserContext parserContext,
Node currentNode,
BodyTranslator methodBodyTranslator) {
super(context, source, parserContext, currentNode);
super(language, source, parserContext, currentNode);
this.methodBodyTranslator = methodBodyTranslator;
}

Expand Down
7 changes: 2 additions & 5 deletions src/main/java/org/truffleruby/parser/Translator.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.Arrays;
import java.util.List;

import org.truffleruby.RubyContext;
import org.truffleruby.RubyLanguage;
import org.truffleruby.language.RubyNode;
import org.truffleruby.language.SourceIndexLength;
Expand All @@ -37,15 +36,13 @@

public abstract class Translator extends AbstractNodeVisitor<RubyNode> {

protected final RubyContext context;
protected final Source source;
protected final ParserContext parserContext;
protected final Node currentNode;
protected final RubyLanguage language;

public Translator(RubyContext context, Source source, ParserContext parserContext, Node currentNode) {
this.context = context;
this.language = context.getLanguageSlow();
public Translator(RubyLanguage language, Source source, ParserContext parserContext, Node currentNode) {
this.language = language;
this.source = source;
this.parserContext = parserContext;
this.currentNode = currentNode;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/truffleruby/parser/TranslatorDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public RubyRootNode parse(RubySource rubySource, ParserContext parserContext, St
}

final BodyTranslator translator = new BodyTranslator(
context,
language,
null,
environment,
source,
Expand Down

0 comments on commit 169bce9

Please sign in to comment.