Skip to content

Commit f1defbf

Browse files
committed
Move fileLine and filenameLine to RubyLanguage
1 parent c8160f0 commit f1defbf

File tree

17 files changed

+55
-56
lines changed

17 files changed

+55
-56
lines changed

src/main/java/org/truffleruby/RubyContext.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
import com.oracle.truffle.api.instrumentation.Instrumenter;
9494
import com.oracle.truffle.api.nodes.IndirectCallNode;
9595
import com.oracle.truffle.api.source.Source;
96-
import com.oracle.truffle.api.source.SourceSection;
9796

9897
public class RubyContext {
9998

@@ -825,35 +824,4 @@ public PrintStream getEnvErrStream() {
825824
return errStream;
826825
}
827826

828-
@TruffleBoundary
829-
public static String fileLine(SourceSection section) {
830-
if (section == null) {
831-
return "no source section";
832-
} else {
833-
final String path = RubyLanguage.getPath(section.getSource());
834-
835-
if (section.isAvailable()) {
836-
return path + ":" + section.getStartLine();
837-
} else {
838-
return path;
839-
}
840-
}
841-
}
842-
843-
@TruffleBoundary
844-
public static String filenameLine(SourceSection section) {
845-
if (section == null) {
846-
return "no source section";
847-
} else {
848-
final String path = RubyLanguage.getPath(section.getSource());
849-
final String filename = new File(path).getName();
850-
851-
if (section.isAvailable()) {
852-
return filename + ":" + section.getStartLine();
853-
} else {
854-
return filename;
855-
}
856-
}
857-
}
858-
859827
}

src/main/java/org/truffleruby/RubyLanguage.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.oracle.truffle.api.instrumentation.AllocationReporter;
2222
import com.oracle.truffle.api.object.Shape;
2323
import com.oracle.truffle.api.source.Source;
24+
import com.oracle.truffle.api.source.SourceSection;
2425
import org.graalvm.options.OptionDescriptors;
2526
import org.jcodings.Encoding;
2627
import org.truffleruby.builtins.PrimitiveManager;
@@ -235,6 +236,37 @@ public RubyLanguage() {
235236
frozenStringLiterals = new FrozenStringLiterals(ropeCache);
236237
}
237238

239+
@TruffleBoundary
240+
public static String fileLine(SourceSection section) {
241+
if (section == null) {
242+
return "no source section";
243+
} else {
244+
final String path = getPath(section.getSource());
245+
246+
if (section.isAvailable()) {
247+
return path + ":" + section.getStartLine();
248+
} else {
249+
return path;
250+
}
251+
}
252+
}
253+
254+
@TruffleBoundary
255+
public static String filenameLine(SourceSection section) {
256+
if (section == null) {
257+
return "no source section";
258+
} else {
259+
final String path = getPath(section.getSource());
260+
final String filename = new File(path).getName();
261+
262+
if (section.isAvailable()) {
263+
return filename + ":" + section.getStartLine();
264+
} else {
265+
return filename;
266+
}
267+
}
268+
}
269+
238270
@TruffleBoundary
239271
public RubySymbol getSymbol(String string) {
240272
return symbolTable.getSymbol(string);

src/main/java/org/truffleruby/builtins/PrimitiveNodeConstructor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
package org.truffleruby.builtins;
1111

12-
import org.truffleruby.RubyContext;
12+
import org.truffleruby.RubyLanguage;
1313
import org.truffleruby.core.array.ArrayUtils;
1414
import org.truffleruby.core.numeric.FixnumLowerNodeGen;
1515
import org.truffleruby.core.support.TypeNodes;
@@ -39,7 +39,7 @@ public RubyNode createInvokePrimitiveNode(Source source, SourceIndexLength sourc
3939
if (arguments.length != getPrimitiveArity()) {
4040
throw new Error(
4141
"Incorrect number of arguments (expected " + getPrimitiveArity() + ") at " +
42-
RubyContext.fileLine(sourceSection.toSourceSection(source)));
42+
RubyLanguage.fileLine(sourceSection.toSourceSection(source)));
4343
}
4444

4545
for (int n = 0; n < arguments.length; n++) {

src/main/java/org/truffleruby/core/fiber/FiberManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private void fiberMain(RubyContext context, RubyFiber fiber, RubyProc block, Nod
145145
final Thread thread = Thread.currentThread();
146146
final SourceSection sourceSection = block.sharedMethodInfo.getSourceSection();
147147
final String oldName = thread.getName();
148-
thread.setName(NAME_PREFIX + " id=" + thread.getId() + " from " + RubyContext.fileLine(sourceSection));
148+
thread.setName(NAME_PREFIX + " id=" + thread.getId() + " from " + RubyLanguage.fileLine(sourceSection));
149149

150150
start(fiber, thread, false);
151151

src/main/java/org/truffleruby/core/module/ModuleFields.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public void setAutoloadConstant(RubyContext context, Node currentNode, String na
365365
if (context.getOptions().LOG_AUTOLOAD) {
366366
RubyLanguage.LOGGER.info(() -> String.format(
367367
"%s: setting up autoload %s with %s",
368-
RubyContext.fileLine(context.getCallStack().getTopMostUserSourceSection()),
368+
RubyLanguage.fileLine(context.getCallStack().getTopMostUserSourceSection()),
369369
autoloadConstant,
370370
filename));
371371
}

src/main/java/org/truffleruby/core/thread/ThreadNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public abstract static class ThreadInitializeNode extends PrimitiveArrayArgument
362362
protected Object initialize(RubyThread thread, RubyArray arguments, RubyProc block,
363363
@CachedLibrary("arguments.store") ArrayStoreLibrary stores) {
364364
final SourceSection sourceSection = block.sharedMethodInfo.getSourceSection();
365-
final String info = RubyContext.fileLine(sourceSection);
365+
final String info = RubyLanguage.fileLine(sourceSection);
366366
final int argSize = arguments.size;
367367
final Object[] args = stores.boxedCopyOfRange(arguments.store, 0, argSize);
368368
final String sharingReason = "creating Ruby Thread " + info;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private void log(RubyContext context, String message) {
7575

7676
final String displayedWarning = String.format(
7777
"%s: %s",
78-
RubyContext.fileLine(userSourceSection),
78+
RubyLanguage.fileLine(userSourceSection),
7979
message);
8080

8181
if (DISPLAYED_WARNINGS.add(displayedWarning)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,6 @@ public RubyArray createEmptyArray() {
130130

131131
@Override
132132
public String toString() {
133-
return super.toString() + " at " + RubyContext.fileLine(getSourceSection());
133+
return super.toString() + " at " + RubyLanguage.fileLine(getSourceSection());
134134
}
135135
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public Object isDefined(VirtualFrame frame, RubyLanguage language, RubyContext c
3535

3636
@Override
3737
public String toString() {
38-
return super.toString() + " at " + RubyContext.fileLine(getSourceSection());
38+
return super.toString() + " at " + RubyLanguage.fileLine(getSourceSection());
3939
}
4040

4141
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static void callWarn(RubyContext context, SourceSection sourceSection, String me
7272

7373
@TruffleBoundary
7474
private static String buildWarningMessage(SourceSection sourceSection, String message) {
75-
final String sourceLocation = sourceSection != null ? RubyContext.fileLine(sourceSection) + ": " : "";
75+
final String sourceLocation = sourceSection != null ? RubyLanguage.fileLine(sourceSection) + ": " : "";
7676
return sourceLocation + "warning: " + message;
7777
}
7878

0 commit comments

Comments
 (0)