Skip to content

Commit 5cd41a1

Browse files
committed
Remove SourceIndexLength class and its usage
1 parent d1c18af commit 5cd41a1

File tree

4 files changed

+5
-114
lines changed

4 files changed

+5
-114
lines changed

src/main/java/org/truffleruby/language/RubyNode.java

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public abstract class RubyNode extends RubyBaseNodeWithExecute implements Instru
5757
private static final byte FLAG_ROOT = 3; // 1<<3 = 8
5858

5959
protected static final int NO_SOURCE = -1;
60+
private static final int UNAVAILABLE_SOURCE_SECTION_LENGTH = -1;
6061

6162
// Used when the return value of a node is ignored syntactically.
6263
// Returns Nil instead of void to force RubyNodeWrapper to call `delegateNode.executeVoid(frame)`, otherwise
@@ -85,21 +86,13 @@ public boolean hasSource() {
8586
return isAdoptable() && getSourceCharIndex() != NO_SOURCE;
8687
}
8788

88-
public void unsafeSetSourceSection(SourceIndexLength sourceIndexLength) {
89-
assert !hasSource();
90-
91-
if (sourceIndexLength != null) {
92-
unsafeSetSourceSection(sourceIndexLength.getCharIndex(), sourceIndexLength.getLength());
93-
}
94-
}
95-
9689
public void unsafeSetSourceSection(SourceSection sourceSection) {
9790
assert !hasSource();
9891

9992
if (sourceSection.isAvailable()) {
10093
unsafeSetSourceSection(sourceSection.getCharIndex(), sourceSection.getCharLength());
10194
} else {
102-
unsafeSetSourceSection(0, SourceIndexLength.UNAVAILABLE);
95+
unsafeSetSourceSection(0, UNAVAILABLE_SOURCE_SECTION_LENGTH);
10396
}
10497
}
10598

@@ -121,14 +114,6 @@ public RubyNode copySourceSection(RubyNode from) {
121114
return this;
122115
}
123116

124-
public SourceIndexLength getSourceIndexLength() {
125-
if (!hasSource()) {
126-
return null;
127-
} else {
128-
return new SourceIndexLength(getSourceCharIndex(), getSourceLength());
129-
}
130-
}
131-
132117
@Override
133118
@TruffleBoundary
134119
public SourceSection getSourceSection() {
@@ -141,7 +126,7 @@ public SourceSection getSourceSection() {
141126
}
142127

143128
int sourceLength = getSourceLength();
144-
if (sourceLength == SourceIndexLength.UNAVAILABLE) {
129+
if (sourceLength == UNAVAILABLE_SOURCE_SECTION_LENGTH) {
145130
return source.createUnavailableSection();
146131
} else {
147132
return source.createSection(getSourceCharIndex(), sourceLength);
@@ -166,23 +151,6 @@ private Source getSource() {
166151
return sourceSection.getSource();
167152
}
168153

169-
public SourceIndexLength getEncapsulatingSourceIndexLength() {
170-
Node node = this;
171-
while (node != null) {
172-
if (node instanceof RubyNode && ((RubyNode) node).hasSource()) {
173-
return ((RubyNode) node).getSourceIndexLength();
174-
}
175-
176-
if (node instanceof RootNode) {
177-
return SourceIndexLength.fromSourceSection(node.getSourceSection());
178-
}
179-
180-
node = node.getParent();
181-
}
182-
183-
return null;
184-
}
185-
186154
@Override
187155
public String toString() {
188156
return super.toString() + " at " + RubyLanguage.fileLineRange(getSourceSection());

src/main/java/org/truffleruby/language/SourceIndexLength.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@
163163
import static org.truffleruby.parser.TranslatorEnvironment.FORWARDED_KEYWORD_REST_NAME;
164164
import static org.truffleruby.parser.TranslatorEnvironment.FORWARDED_REST_NAME;
165165

166-
// NOTE: we should avoid SourceIndexLength in YARPTranslator, instead pass a Nodes.Node as location, because
167-
// * it does not copy the newline flag properly,
168-
// * it is inefficient,
169-
// * there is typically no need for such an object since YARP location info is correct.
170-
171166
/** Translate (or convert) AST provided by a parser (YARP parser) to Truffle AST.
172167
*
173168
* The main translator that delegates handling of some nodes (e.g. method or block definition) to helper translators.

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
import org.truffleruby.language.RubyRootNode;
6868
import org.truffleruby.language.RubyTopLevelRootNode;
6969
import org.truffleruby.language.SetTopLevelBindingNode;
70-
import org.truffleruby.language.SourceIndexLength;
7170
import org.truffleruby.language.arguments.MissingArgumentBehavior;
7271
import org.truffleruby.language.arguments.ReadPreArgumentNode;
7372
import org.truffleruby.language.arguments.RubyArguments;
@@ -171,7 +170,6 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
171170
final SourceSection sourceSection = rubySource.getBytes().length == 0
172171
? source.createUnavailableSection()
173172
: source.createSection(0, rubySource.getBytes().length);
174-
final SourceIndexLength sourceIndexLength = SourceIndexLength.fromSourceSection(sourceSection);
175173

176174
final String modulePath = staticLexicalScope == null || staticLexicalScope == context.getRootLexicalScope()
177175
? null
@@ -311,7 +309,7 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
311309
if (parserContext.isTopLevel()) {
312310
rootNode = new RubyTopLevelRootNode(
313311
language,
314-
sourceIndexLength.toSourceSection(source),
312+
sourceSection,
315313
frameDescriptor,
316314
sharedMethodInfo,
317315
truffleNode,
@@ -321,7 +319,7 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
321319
} else {
322320
rootNode = new RubyEvalRootNode(
323321
language,
324-
sourceIndexLength.toSourceSection(source),
322+
sourceSection,
325323
frameDescriptor,
326324
sharedMethodInfo,
327325
truffleNode,

0 commit comments

Comments
 (0)