Skip to content

Commit

Permalink
Symbol is being invaded by RubySymbol. Some more mandatory old API re…
Browse files Browse the repository at this point in the history
…movals as

there is no way some of this backwards compat can be maintained.
enebo committed Jul 19, 2017
1 parent 570eac5 commit a714158
Showing 11 changed files with 90 additions and 111 deletions.
11 changes: 2 additions & 9 deletions core/src/main/java/org/jruby/ast/DefnNode.java
Original file line number Diff line number Diff line change
@@ -34,28 +34,21 @@

import java.util.List;

import org.jruby.RubySymbol;
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.parser.StaticScope;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* method definition node.
*/
public class DefnNode extends MethodDefNode implements INameNode {
public DefnNode(ISourcePosition position, ByteList name, ArgsNode argsNode,
public DefnNode(ISourcePosition position, RubySymbol name, ArgsNode argsNode,
StaticScope scope, Node bodyNode, int endLine) {
super(position, name, argsNode, scope, bodyNode, endLine);
}

@Deprecated
public DefnNode(ISourcePosition position, String name, ArgsNode argsNode,
StaticScope scope, Node bodyNode, int endLine) {
super(position, StringSupport.stringAsByteList(name), argsNode, scope, bodyNode, endLine);
}

public NodeType getNodeType() {
return NodeType.DEFNNODE;
}
15 changes: 2 additions & 13 deletions core/src/main/java/org/jruby/ast/DefsNode.java
Original file line number Diff line number Diff line change
@@ -33,20 +33,19 @@

import java.util.List;

import org.jruby.RubySymbol;
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.parser.StaticScope;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Represents a singleton method definition.
*/
public class DefsNode extends MethodDefNode implements INameNode {
private final Node receiverNode;

public DefsNode(ISourcePosition position, Node receiverNode, ByteList name, ArgsNode argsNode,
public DefsNode(ISourcePosition position, Node receiverNode, RubySymbol name, ArgsNode argsNode,
StaticScope scope, Node bodyNode, int endLine) {
super(position, name, argsNode, scope, bodyNode, endLine);

@@ -55,16 +54,6 @@ public DefsNode(ISourcePosition position, Node receiverNode, ByteList name, Args
this.receiverNode = receiverNode;
}

@Deprecated
public DefsNode(ISourcePosition position, Node receiverNode, String name, ArgsNode argsNode,
StaticScope scope, Node bodyNode, int endLine) {
super(position, StringSupport.stringAsByteList(name), argsNode, scope, bodyNode, endLine);

assert receiverNode != null : "receiverNode is not null";

this.receiverNode = receiverNode;
}

public NodeType getNodeType() {
return NodeType.DEFSNODE;
}
14 changes: 4 additions & 10 deletions core/src/main/java/org/jruby/ast/LiteralNode.java
Original file line number Diff line number Diff line change
@@ -3,10 +3,9 @@
import java.util.List;


import org.jruby.RubySymbol;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* This is not a node in the classic sense in that it has no defined or
@@ -17,20 +16,15 @@
* subtype which is not Object.
*/
public class LiteralNode extends Node implements InvisibleNode {
private ByteList name;
private RubySymbol name;

public LiteralNode(ISourcePosition position, ByteList name) {
public LiteralNode(ISourcePosition position, RubySymbol name) {
super(position, false);
this.name = name;
}

@Deprecated
public LiteralNode(ISourcePosition position, String name) {
this(position, StringSupport.stringAsByteList(name));
}

public String getName() {
return StringSupport.byteListAsString(name);
return name.asJavaString();
}

/**
22 changes: 13 additions & 9 deletions core/src/main/java/org/jruby/ast/MethodDefNode.java
Original file line number Diff line number Diff line change
@@ -28,23 +28,23 @@
***** END LICENSE BLOCK *****/
package org.jruby.ast;

/**
* Base class for DefnNode and DefsNode
*/
import org.jruby.ast.types.INameNode;
import org.jruby.RubySymbol;
import org.jruby.ast.types.ISymbolNameNode;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.parser.StaticScope;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

public abstract class MethodDefNode extends Node implements INameNode, DefNode {
protected final ByteList name;
/**
* Base class for DefnNode and DefsNode
*/
public abstract class MethodDefNode extends Node implements ISymbolNameNode, DefNode {
protected final RubySymbol name;
protected final ArgsNode argsNode;
protected final StaticScope scope;
protected final Node bodyNode;
protected final int endLine;

public MethodDefNode(ISourcePosition position, ByteList name, ArgsNode argsNode,
public MethodDefNode(ISourcePosition position, RubySymbol name, ArgsNode argsNode,
StaticScope scope, Node bodyNode, int endLine) {
super(position, bodyNode.containsVariableAssignment());

@@ -89,10 +89,14 @@ public Node getBodyNode() {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
return name.asJavaString();
}

public ByteList getByteName() {
return name.getBytes();
}

public RubySymbol getSymbolName() {
return name;
}

3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ast/OpAsgnConstDeclNode.java
Original file line number Diff line number Diff line change
@@ -47,9 +47,10 @@ public <T> T accept(NodeVisitor<T> visitor) {
return visitor.visitOpAsgnConstDeclNode(this);
}

// FIXME: Missing operator as a node.
@Override
public List<Node> childNodes() {
return createList(lhs, new LiteralNode(getPosition(), operator), rhs);
return createList(lhs, rhs);
}

@Override
18 changes: 5 additions & 13 deletions core/src/main/java/org/jruby/ast/SymbolNode.java
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@

import org.jcodings.Encoding;

import org.jruby.RubySymbol;
import org.jruby.ast.types.ILiteralNode;
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
@@ -47,14 +48,9 @@
* Represents a symbol (:symbol_name).
*/
public class SymbolNode extends Node implements ILiteralNode, INameNode, SideEffectFree {
private final ByteList name;
private final RubySymbol name;

@Deprecated
public SymbolNode(ISourcePosition position, String name, Encoding encoding, int cr) {
this(position, new ByteList(name.getBytes(encoding.getCharset()), encoding));
}

public SymbolNode(ISourcePosition position, ByteList value) {
public SymbolNode(ISourcePosition position, RubySymbol value) {
super(position, false);

this.name = value;
@@ -79,22 +75,18 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
return name.asJavaString();
}

public Encoding getEncoding() {
return name.getEncoding();
}

public ByteList getByteName() {
return name;
return name.getBytes();
}

public List<Node> childNodes() {
return EMPTY_LIST;
}

public ByteList getBytes() {
return name;
}
}
4 changes: 1 addition & 3 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -3817,9 +3817,7 @@ public Operand buildSValue(SValueNode node) {
}

public Operand buildSymbol(SymbolNode node) {
// Since symbols are interned objects, no need to copyAndReturnValue(...)
// SSS FIXME: Premature opt?
return new Symbol(node.getBytes());
return new Symbol(node.getByteName());
}

public Operand buildTrue() {
9 changes: 2 additions & 7 deletions core/src/main/java/org/jruby/parser/ParserSupport.java
Original file line number Diff line number Diff line change
@@ -1118,16 +1118,11 @@ public KeyValuePair<Node, Node> createKeyValue(Node key, Node value) {
}

public Node asSymbol(ISourcePosition position, ByteList value) {
return new SymbolNode(position, value);
}

@Deprecated
public Node asSymbol(ISourcePosition position, String value) {
return new SymbolNode(position, value, lexer.getEncoding(), lexer.getTokenCR());
return new SymbolNode(position, symbol(value));
}

public Node asSymbol(ISourcePosition position, Node value) {
return value instanceof StrNode ? new SymbolNode(position, ((StrNode) value).getValue()) :
return value instanceof StrNode ? new SymbolNode(position, symbol(((StrNode) value).getValue())) :
new DSymbolNode(position, (DStrNode) value);
}

Loading

0 comments on commit a714158

Please sign in to comment.