Skip to content

Commit 10b5059

Browse files
eregonandrykonchin
authored andcommitted
Avoid SourceIndexLength in YARPTranslator
1 parent 60efa87 commit 10b5059

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.truffleruby.language.RubyNode;
4343
import org.truffleruby.language.RubyRootNode;
4444
import org.truffleruby.language.RubyTopLevelRootNode;
45-
import org.truffleruby.language.SourceIndexLength;
4645
import org.truffleruby.language.arguments.EmptyArgumentsDescriptor;
4746
import org.truffleruby.language.arguments.ProfileArgumentNodeGen;
4847
import org.truffleruby.language.arguments.ReadSelfNode;
@@ -117,8 +116,10 @@
117116
import java.util.Deque;
118117
import java.util.List;
119118

120-
// NOTE: we should avoid SourceIndexLength in YARPTranslator, instead pass a Nodes.Node as location,
121-
// because that's inefficient and there is typically no need for such an object since YARP location info is correct.
119+
// NOTE: we should avoid SourceIndexLength in YARPTranslator, instead pass a Nodes.Node as location, because
120+
// * it does not copy the newline flag properly,
121+
// * it is inefficient,
122+
// * there is typically no need for such an object since YARP location info is correct.
122123

123124
/** Translate (or convert) AST provided by a parser (YARP parser) to Truffle AST */
124125
public final class YARPTranslator extends AbstractNodeVisitor<RubyNode> {
@@ -1017,24 +1018,23 @@ public RubyNode visitLocalVariableOperatorWriteNode(Nodes.LocalVariableOperatorW
10171018
}
10181019

10191020
public RubyNode visitLocalVariableReadNode(Nodes.LocalVariableReadNode node) {
1020-
final SourceIndexLength sourceSection = new SourceIndexLength(node.startOffset, node.length);
10211021
final String name = toString(node);
10221022

1023-
final RubyNode rubyNode = environment.findLocalVarNode(name, sourceSection);
1023+
final RubyNode rubyNode = environment.findLocalVarNode(name, null);
10241024
assert rubyNode != null : name;
10251025

1026+
assignNodePositionInSource(node, rubyNode);
10261027
return rubyNode;
10271028
}
10281029

10291030
public RubyNode visitLocalVariableWriteNode(Nodes.LocalVariableWriteNode node) {
1030-
final SourceIndexLength sourceSection = new SourceIndexLength(node.startOffset, node.length);
10311031
final String name = toString(node.name_loc);
10321032

10331033
if (environment.getNeverAssignInParentScope()) {
10341034
environment.declareVar(name);
10351035
}
10361036

1037-
ReadLocalNode lhs = environment.findLocalVarNode(name, sourceSection);
1037+
ReadLocalNode lhs = environment.findLocalVarNode(name, null);
10381038

10391039
// TODO: it should always be present if we use byte[][] locals
10401040
if (lhs == null) {
@@ -1044,7 +1044,7 @@ public RubyNode visitLocalVariableWriteNode(Nodes.LocalVariableWriteNode node) {
10441044
}
10451045
environmentToDeclareIn.declareVar(name);
10461046

1047-
lhs = environment.findLocalVarNode(name, sourceSection);
1047+
lhs = environment.findLocalVarNode(name, null);
10481048

10491049
if (lhs == null) {
10501050
throw CompilerDirectives.shouldNotReachHere();

0 commit comments

Comments
 (0)