Skip to content

Commit

Permalink
Showing 7 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ast/ConstDeclNode.java
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return name
*/
public String getName() {
return name == null ? constNode.getName() : StringSupport.byteListAsString(name);
return StringSupport.byteListAsString(getByteName());
}

public ByteList getByteName() {
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ast/Node.java
Original file line number Diff line number Diff line change
@@ -147,7 +147,7 @@ public String toString(boolean indent, int indentation) {

if (moreState != null) builder.append("[").append(moreState).append("]");

if (this instanceof INameNode) builder.append(":").append(((INameNode) this).getName());
if (this instanceof INameNode) builder.append(":").append(((INameNode) this).getByteName());

builder.append(" ").append(getPosition().getLine());

10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/ast/OptArgNode.java
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@
public class OptArgNode extends Node implements INameNode {
private Node value;

// value must be LocalAsgnNode or DAsgnNode which is an INameNode
public OptArgNode(ISourcePosition position, Node value) {
super(position, value != null && value.containsVariableAssignment());
this.value = value;
@@ -50,7 +51,7 @@ public NodeType getNodeType() {
}

public Node getValue() {
return value;
return (Node) value;
}

@Override
@@ -60,15 +61,14 @@ public Object accept(NodeVisitor visitor) {

@Override
public List<Node> childNodes() {
return Node.createList(value);
return Node.createList(getValue());
}

public String getName() {
// FIXME: When is this not a INameNode?
return value instanceof INameNode ? ((INameNode) value).getName() : null;
return getByteName().toString();
}

public ByteList getByteName() {
return value instanceof INameNode ? ((INameNode) value).getByteName() : null;
return ((INameNode) value).getByteName();
}
}
8 changes: 7 additions & 1 deletion core/src/main/java/org/jruby/ast/RestArgNode.java
Original file line number Diff line number Diff line change
@@ -31,18 +31,24 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;

/*
* The rest argument for a method (def foo(a, *b, c)).
*/
public class RestArgNode extends ArgumentNode implements INameNode {
@Deprecated
public RestArgNode(ISourcePosition position, String name, int index) {
super(position, name, index);
}

public RestArgNode(ISourcePosition position, ByteList name, int index) {
super(position, name, index);
}

// 1.9 only - lvar assign logic returns an Argument node
public RestArgNode(ArgumentNode argNode) {
this(argNode.getPosition(), argNode.getName(), argNode.getIndex());
super(argNode.getPosition(), argNode.getByteName(), argNode.getIndex());
}

@Override
8 changes: 7 additions & 1 deletion core/src/main/java/org/jruby/ast/UnnamedRestArgNode.java
Original file line number Diff line number Diff line change
@@ -29,21 +29,27 @@
package org.jruby.ast;

import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;

/**
* a bare '*' or nothing. Name is "" if it is '*' and null if it is nothing.
*/
public class UnnamedRestArgNode extends RestArgNode {
@Deprecated
public UnnamedRestArgNode(ISourcePosition position, String name, int index) {
super(position, name, index);
}

public UnnamedRestArgNode(ISourcePosition position, ByteList name, int index) {
super(position, name, index);
}

public boolean isStar() {
return getByteName() != null;
}

@Override
public String getName() {
return isStar() ? super.getName() : null;
return isStar() ? super.getByteName().toString() : null;
}
}
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/parser/RubyParser.java
Original file line number Diff line number Diff line change
@@ -4122,8 +4122,8 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
};
states[394] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
RestArgNode rest = new UnnamedRestArgNode(((ListNode)yyVals[-1+yyTop]).getPosition(), null, support.getCurrentScope().addVariable("*"));
yyVal = support.new_args(((ListNode)yyVals[-1+yyTop]).getPosition(), ((ListNode)yyVals[-1+yyTop]), null, rest, null, (ArgsTailHolder) null);
RestArgNode rest = new UnnamedRestArgNode(((ListNode)yyVals[-1+yyTop]).getPosition(), null, support.getCurrentScope().addVariable(new ByteList(new byte[] {'*'})));
yyVal = support.new_args(((ListNode)yyVals[-1+yyTop]).getPosition(), ((ListNode)yyVals[-1+yyTop]), null, rest, null, (ArgsTailHolder) null);
return yyVal;
}
};
@@ -5439,7 +5439,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
};
states[597] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = new UnnamedRestArgNode(lexer.getPosition(), "", support.getCurrentScope().addVariable("*"));
yyVal = new UnnamedRestArgNode(lexer.getPosition(), new ByteList(), support.getCurrentScope().addVariable(new ByteList(new byte[] {'*'})));
return yyVal;
}
};
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/parser/RubyParser.y
Original file line number Diff line number Diff line change
@@ -1754,8 +1754,8 @@ block_param : f_arg ',' f_block_optarg ',' f_rest_arg opt_block_args_tail {
$$ = support.new_args($1.getPosition(), $1, null, $3, null, $4);
}
| f_arg ',' {
RestArgNode rest = new UnnamedRestArgNode($1.getPosition(), null, support.getCurrentScope().addVariable("*"));
$$ = support.new_args($1.getPosition(), $1, null, rest, null, (ArgsTailHolder) null);
RestArgNode rest = new UnnamedRestArgNode($1.getPosition(), null, support.getCurrentScope().addVariable(new ByteList(new byte[] {'*'})));
$$ = support.new_args($1.getPosition(), $1, null, rest, null, (ArgsTailHolder) null);
}
| f_arg ',' f_rest_arg ',' f_arg opt_block_args_tail {
$$ = support.new_args($1.getPosition(), $1, null, $3, $5, $6);
@@ -2571,7 +2571,7 @@ f_rest_arg : restarg_mark tIDENTIFIER {
$$ = new RestArgNode(support.arg_var(support.shadowing_lvar($2)));
}
| restarg_mark {
$$ = new UnnamedRestArgNode(lexer.getPosition(), "", support.getCurrentScope().addVariable("*"));
$$ = new UnnamedRestArgNode(lexer.getPosition(), new ByteList(), support.getCurrentScope().addVariable(new ByteList(new byte[] {'*'})));
}

// [!null]

0 comments on commit a6fac6a

Please sign in to comment.