Skip to content

Commit

Permalink
[Truffle] Fix SourceSection identifier for def* nodes.
Browse files Browse the repository at this point in the history
* getIdentifier() does not work there as getNamedMethodName()
  is inappropriate there: it is the class name and not the method we are defining.
  • Loading branch information
eregon committed Mar 19, 2015
1 parent de120ca commit f804dce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Expand Up @@ -1049,7 +1049,7 @@ public RubyNode visitDefinedNode(org.jruby.ast.DefinedNode node) {

@Override
public RubyNode visitDefnNode(org.jruby.ast.DefnNode node) {
final SourceSection sourceSection = translate(node.getPosition());
final SourceSection sourceSection = translate(node.getPosition(), node.getName());
final RubyNode classNode;

if (parent == null) {
Expand All @@ -1072,7 +1072,7 @@ public RubyNode visitDefnNode(org.jruby.ast.DefnNode node) {

@Override
public RubyNode visitDefsNode(org.jruby.ast.DefsNode node) {
final SourceSection sourceSection = translate(node.getPosition());
final SourceSection sourceSection = translate(node.getPosition(), node.getName());

final RubyNode objectNode = node.getReceiverNode().accept(this);

Expand Down
Expand Up @@ -78,7 +78,7 @@ public MethodDefinitionNode compileClassNode(SourceSection sourceSection, String

@Override
public RubyNode visitDefnNode(org.jruby.ast.DefnNode node) {
final SourceSection sourceSection = translate(node.getPosition());
final SourceSection sourceSection = translate(node.getPosition(), node.getName());
final SelfNode classNode = new SelfNode(context, sourceSection);
return translateMethodDefinition(sourceSection, classNode, node.getName(), node, node.getArgsNode(), node.getBodyNode());
}
Expand Down
15 changes: 10 additions & 5 deletions truffle/src/main/java/org/jruby/truffle/translator/Translator.java
Expand Up @@ -12,6 +12,7 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.lexer.yacc.DetailedSourcePosition;
import org.jruby.lexer.yacc.InvalidSourcePosition;
import org.jruby.truffle.nodes.RubyNode;
Expand Down Expand Up @@ -43,10 +44,14 @@ public Translator(Node currentNode, RubyContext context, Source source) {
}

protected SourceSection translate(org.jruby.lexer.yacc.ISourcePosition sourcePosition) {
return translate(source, sourcePosition);
return translate(source, sourcePosition, getIdentifier());
}

protected SourceSection translate(org.jruby.lexer.yacc.ISourcePosition sourcePosition, String identifier) {
return translate(source, sourcePosition, identifier);
}

public SourceSection translate(Source source, org.jruby.lexer.yacc.ISourcePosition sourcePosition) {
private SourceSection translate(Source source, org.jruby.lexer.yacc.ISourcePosition sourcePosition, String identifier) {
if (sourcePosition == InvalidSourcePosition.INSTANCE) {
if (parentSourceSection.peek() == null) {
throw new UnsupportedOperationException("Truffle doesn't want invalid positions - find a way to give me a real position!");
Expand All @@ -57,13 +62,13 @@ public SourceSection translate(Source source, org.jruby.lexer.yacc.ISourcePositi
final DetailedSourcePosition detailedSourcePosition = (DetailedSourcePosition) sourcePosition;

try {
return source.createSection(getIdentifier(), detailedSourcePosition.getOffset(), detailedSourcePosition.getLength());
return source.createSection(identifier, detailedSourcePosition.getOffset(), detailedSourcePosition.getLength());
} catch (IllegalArgumentException e) {
// In some cases we still get bad offsets with the detailed source positions
return source.createSection(getIdentifier(), sourcePosition.getLine() + 1);
return source.createSection(identifier, sourcePosition.getLine() + 1);
}
} else if (Options.TRUFFLE_ALLOW_SIMPLE_SOURCE_SECTIONS.load()) {
return source.createSection(getIdentifier(), sourcePosition.getLine() + 1);
return source.createSection(identifier, sourcePosition.getLine() + 1);
} else {
throw new UnsupportedOperationException("Truffle needs detailed source positions unless you know what you are doing and set truffle.allow_simple_source_sections - got " + sourcePosition.getClass());
}
Expand Down

0 comments on commit f804dce

Please sign in to comment.