Skip to content

Commit

Permalink
Revert "[Truffle] Reove BodyTranslator.translateCPath()": We need it …
Browse files Browse the repository at this point in the history
…for cases other than unqualified.

This reverts commit e76db94.
  • Loading branch information
eregon committed Nov 10, 2014
1 parent e76db94 commit 8cc02f8
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ public RubyNode visitClassNode(org.jruby.ast.ClassNode node) {

final String name = node.getCPath().getName();

RubyNode lexicalParent = new LexicalScopeNode(context, sourceSection, environment.getLexicalScope());
RubyNode lexicalParent = translateCPath(sourceSection, node.getCPath());

RubyNode superClass;
if (node.getSuperNode() != null) {
Expand Down Expand Up @@ -646,6 +646,16 @@ public RubyNode visitColon3Node(org.jruby.ast.Colon3Node node) {
return new ReadConstantNode(context, sourceSection, node.getName(), root, LexicalScope.NONE);
}

private RubyNode translateCPath(SourceSection sourceSection, org.jruby.ast.Colon3Node node) {
if (node instanceof Colon2ImplicitNode) { // use current lexical scope
return new LexicalScopeNode(context, sourceSection, environment.getLexicalScope());
} else if (node instanceof Colon2ConstNode) { // A::B
return node.childNodes().get(0).accept(this);
} else { // Colon3Node: on top-level (Object)
return new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getObjectClass());
}
}

@Override
public RubyNode visitConstDeclNode(org.jruby.ast.ConstDeclNode node) {
final SourceSection sourceSection = translate(node.getPosition());
Expand Down Expand Up @@ -1307,7 +1317,7 @@ public RubyNode visitModuleNode(org.jruby.ast.ModuleNode node) {

final String name = node.getCPath().getName();

RubyNode lexicalParent = new LexicalScopeNode(context, sourceSection, environment.getLexicalScope());
RubyNode lexicalParent = translateCPath(sourceSection, node.getCPath());

final DefineOrGetModuleNode defineModuleNode = new DefineOrGetModuleNode(context, sourceSection, name, lexicalParent);

Expand Down

0 comments on commit 8cc02f8

Please sign in to comment.