Skip to content

Commit

Permalink
Mega Mega Patch. Parser largely pushes most things as ByteList.
Browse files Browse the repository at this point in the history
Up to this point all things are still being accessed through String versions
of methods from IRBuilder on.  So this should be zero sum...However...there
is a problem I have not figured out yet where I think a RubyHash is getting
messed up.  So there will be at least one more commit before this is fully
zero sum.

I have made all existing methods and deprecated.  They probably will only
work so long as the strings represent 7bit ascii or are utf-8 but since they
are all internal methods no longer used I do not fully care.  If some external
projects are using them then I do not expect they will notice since we have
had mbc issues for years.

I had considered making all identifiers share the source line they exist on
to prevent extra array construction and copying.  It could be changed later.

Also I still make a token string in the lexer and as a side-effect we get
and identifier ByteList.  Once this is fully working we can just delete
token creation code and only use the identifier.
enebo committed May 5, 2017
1 parent 903728b commit c4e7631
Showing 51 changed files with 2,075 additions and 800 deletions.
26 changes: 20 additions & 6 deletions core/src/main/java/org/jruby/ast/ArgumentNode.java
Original file line number Diff line number Diff line change
@@ -33,25 +33,34 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Simple Node for named entities. Things like the name of a method will make a node
* for the name. Also local variables will make a ArgumentNode. In the case of a local
* variable we will also keep a list of it's location.
*/
public class ArgumentNode extends Node implements INameNode {
private String identifier;
private ByteList identifier;
private int location;

@Deprecated
public ArgumentNode(ISourcePosition position, String identifier) {
super(position, false);

this.identifier = identifier;
this.identifier = StringSupport.stringAsByteList(identifier);
}

@Deprecated
public ArgumentNode(ISourcePosition position, String identifier, int location) {
this(position, identifier);
this(position, StringSupport.stringAsByteList(identifier), location);
}

public ArgumentNode(ISourcePosition position, ByteList identifier, int location) {
super(position, false);

this.identifier = identifier;
this.location = location; // All variables should be depth 0 in this case
}

@@ -82,13 +91,18 @@ public int getDepth() {
public int getIndex() {
return location & 0xffff;
}

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

public ByteList getByteName() {
return identifier;
}


@Deprecated
public void setName(String name) {
this.identifier = name;
this.identifier = StringSupport.stringAsByteList(name);
}

public List<Node> childNodes() {
17 changes: 14 additions & 3 deletions core/src/main/java/org/jruby/ast/AttrAssignNode.java
Original file line number Diff line number Diff line change
@@ -33,17 +33,19 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Node that represents an assignment of either an array element or attribute.
*/
public class AttrAssignNode extends Node implements INameNode, IArgumentNode {
protected final Node receiverNode;
private String name;
private ByteList name;
private Node argsNode;
private final boolean isLazy;

public AttrAssignNode(ISourcePosition position, Node receiverNode, String name, Node argsNode, boolean isLazy) {
public AttrAssignNode(ISourcePosition position, Node receiverNode, ByteList name, Node argsNode, boolean isLazy) {
super(position, receiverNode != null && receiverNode.containsVariableAssignment() || argsNode != null && argsNode.containsVariableAssignment());

assert receiverNode != null : "receiverNode is not null";
@@ -58,6 +60,11 @@ public AttrAssignNode(ISourcePosition position, Node receiverNode, String name,
this.isLazy = isLazy;
}

@Deprecated
public AttrAssignNode(ISourcePosition position, Node receiverNode, String name, Node argsNode, boolean isLazy) {
this(position, receiverNode, StringSupport.stringAsByteList(name), argsNode, isLazy);
}

public NodeType getNodeType() {
return NodeType.ATTRASSIGNNODE;
}
@@ -76,9 +83,13 @@ public Object accept(NodeVisitor visitor) {
* @return name
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

/**
* Gets the receiverNode.
* receiverNode is the object on which the method is being called
11 changes: 7 additions & 4 deletions core/src/main/java/org/jruby/ast/BackRefNode.java
Original file line number Diff line number Diff line change
@@ -33,8 +33,10 @@

import java.util.List;

import org.jcodings.specific.USASCIIEncoding;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.DefinedMessage;

/**
@@ -49,14 +51,11 @@ public class BackRefNode extends Node {
* the character which generated the back reference
**/
private final char type;

/** ByteList for the name of this backref global */
private final DefinedMessage definedMessage;

public BackRefNode(ISourcePosition position, int type) {
super(position, false);
this.type = (char) type;
this.definedMessage = DefinedMessage.byText("$" + (char)type);
DefinedMessage.byText("$" + (char)type);
}

public NodeType getNodeType() {
@@ -71,6 +70,10 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
return iVisitor.visitBackRefNode(this);
}

public ByteList getByteName() {
return new ByteList(new byte[] {'$', (byte) type}, USASCIIEncoding.INSTANCE);
}

/**
* Gets the type
*
21 changes: 17 additions & 4 deletions core/src/main/java/org/jruby/ast/BlockArgNode.java
Original file line number Diff line number Diff line change
@@ -36,22 +36,30 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* An explicit block argument (&amp;my_block) in parameter list.
*/
public class BlockArgNode extends Node implements INameNode {
private final int count;
private String name;
private ByteList name;

public BlockArgNode(ISourcePosition position, int count, String name) {
public BlockArgNode(ISourcePosition position, int count, ByteList name) {
super(position, false);
this.count = count;
this.name = name;
}

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


public BlockArgNode(ArgumentNode argNode) {
this(argNode.getPosition(), argNode.getIndex(), argNode.getName());
this(argNode.getPosition(), argNode.getIndex(), argNode.getByteName());
}

public NodeType getNodeType() {
@@ -80,11 +88,16 @@ public int getCount() {
* @return it's name
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

@Deprecated
public void setName(String name) {
this.name = name;
this.name = StringSupport.stringAsByteList(name);
}

public List<Node> childNodes() {
16 changes: 14 additions & 2 deletions core/src/main/java/org/jruby/ast/CallNode.java
Original file line number Diff line number Diff line change
@@ -37,6 +37,8 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* A method or operator call.
@@ -45,20 +47,26 @@ public class CallNode extends Node implements INameNode, IArgumentNode, BlockAcc
private final Node receiverNode;
private Node argsNode;
protected Node iterNode;
private String name;
private ByteList name;
private final boolean isLazy;

public CallNode(ISourcePosition position, Node receiverNode, String name, Node argsNode,
Node iterNode) {
this(position, receiverNode, name, argsNode, iterNode, false);
}

@Deprecated
public CallNode(ISourcePosition position, Node receiverNode, String name, Node argsNode,
Node iterNode, boolean isLazy) {
this(position, receiverNode, StringSupport.stringAsByteList(name), argsNode, iterNode, isLazy);
}

public CallNode(ISourcePosition position, Node receiverNode, ByteList name, Node argsNode,
Node iterNode, boolean isLazy) {
super(position, receiverNode.containsVariableAssignment() ||
argsNode != null && argsNode.containsVariableAssignment() ||
iterNode != null && iterNode.containsVariableAssignment());

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

this.name = name;
@@ -116,6 +124,10 @@ public Node setArgsNode(Node argsNode) {
* @return name
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

17 changes: 14 additions & 3 deletions core/src/main/java/org/jruby/ast/ClassVarAsgnNode.java
Original file line number Diff line number Diff line change
@@ -36,23 +36,30 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Class variable assignment node.
*/
public class ClassVarAsgnNode extends AssignableNode implements INameNode {
private String name;
private ByteList name;

/**
* @param name id of the class variable to assign to
* @param valueNode Node used to compute the new value when the assignment is evaled
*/
public ClassVarAsgnNode(ISourcePosition position, String name, Node valueNode) {
public ClassVarAsgnNode(ISourcePosition position, ByteList name, Node valueNode) {
super(position, valueNode, valueNode != null && valueNode.containsVariableAssignment());

this.name = name;
}

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

public NodeType getNodeType() {
return NodeType.CLASSVARASGNNODE;
}
@@ -70,9 +77,13 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

public List<Node> childNodes() {
return createList(getValueNode());
}
16 changes: 14 additions & 2 deletions core/src/main/java/org/jruby/ast/ClassVarDeclNode.java
Original file line number Diff line number Diff line change
@@ -37,19 +37,27 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Class variable declaration.
*/
@Deprecated
public class ClassVarDeclNode extends AssignableNode implements INameNode {
private String name;
private ByteList name;

public ClassVarDeclNode(ISourcePosition position, String name, Node valueNode) {
public ClassVarDeclNode(ISourcePosition position, ByteList name, Node valueNode) {
super(position, valueNode, valueNode != null && valueNode.containsVariableAssignment());

this.name = name;
}

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

public NodeType getNodeType() {
return NodeType.CLASSVARDECLNODE;
}
@@ -67,6 +75,10 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

20 changes: 16 additions & 4 deletions core/src/main/java/org/jruby/ast/ClassVarNode.java
Original file line number Diff line number Diff line change
@@ -36,18 +36,25 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Access to a class variable.
*/
public class ClassVarNode extends Node implements INameNode, SideEffectFree {
private String name;
private ByteList name;

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

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

public NodeType getNodeType() {
return NodeType.CLASSVARNODE;
}
@@ -65,14 +72,19 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

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


@Deprecated
public void setName(String name) {
this.name = name;
this.name = StringSupport.stringAsByteList(name);
}
}
8 changes: 8 additions & 0 deletions core/src/main/java/org/jruby/ast/Colon2ConstNode.java
Original file line number Diff line number Diff line change
@@ -6,12 +6,20 @@
package org.jruby.ast;

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

/**
*
* @author enebo
*/
public class Colon2ConstNode extends Colon2Node {
public Colon2ConstNode(ISourcePosition position, Node leftNode, ByteList name) {
super(position, leftNode, name);

assert leftNode != null: "Colon2ConstNode cannot have null leftNode";
}

@Deprecated
public Colon2ConstNode(ISourcePosition position, Node leftNode, String name) {
super(position, leftNode, name);

6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/ast/Colon2ImplicitNode.java
Original file line number Diff line number Diff line change
@@ -29,13 +29,19 @@
package org.jruby.ast;

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

/**
* Represents a bare class declaration (e.g. class Foo/module Foo). This is slightly misnamed
* since it contains no double colons (::), but our cname production needs to be a common type.
* In JRuby 2, we will rename this.
*/
public class Colon2ImplicitNode extends Colon2Node {
public Colon2ImplicitNode(ISourcePosition position, ByteList name) {
super(position, null, name);
}

@Deprecated
public Colon2ImplicitNode(ISourcePosition position, String name) {
super(position, null, name);
}
9 changes: 8 additions & 1 deletion core/src/main/java/org/jruby/ast/Colon2Node.java
Original file line number Diff line number Diff line change
@@ -36,18 +36,25 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Represents a '::' constant access or method call (Java::JavaClass).
*/
public abstract class Colon2Node extends Colon3Node implements INameNode {
protected final Node leftNode;

public Colon2Node(ISourcePosition position, Node leftNode, String name) {
public Colon2Node(ISourcePosition position, Node leftNode, ByteList name) {
super(position, name, leftNode != null && leftNode.containsVariableAssignment);
this.leftNode = leftNode;
}

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

public NodeType getNodeType() {
return NodeType.COLON2NODE;
}
19 changes: 15 additions & 4 deletions core/src/main/java/org/jruby/ast/Colon3Node.java
Original file line number Diff line number Diff line change
@@ -36,19 +36,26 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Global scope node (::FooBar). This is used to gain access to the global scope (that of the
* Object class) when referring to a constant or method.
*/
public class Colon3Node extends Node implements INameNode {
protected String name;
protected ByteList name;

public Colon3Node(ISourcePosition position, String name) {
public Colon3Node(ISourcePosition position, ByteList name) {
this(position, name, false);
}

protected Colon3Node(ISourcePosition position, String name, boolean containsAssignment) {
@Deprecated
public Colon3Node(ISourcePosition position, String name) {
this(position, StringSupport.stringAsByteList(name), false);
}

protected Colon3Node(ISourcePosition position, ByteList name, boolean containsAssignment) {
super(position, containsAssignment);
this.name = name;
}
@@ -70,6 +77,10 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

@@ -78,6 +89,6 @@ public List<Node> childNodes() {
}

public void setName(String name) {
this.name = name;
this.name = StringSupport.stringAsByteList(name);
}
}
19 changes: 15 additions & 4 deletions core/src/main/java/org/jruby/ast/ConstDeclNode.java
Original file line number Diff line number Diff line change
@@ -36,22 +36,29 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Declaration (and assignment) of a Constant.
*/
public class ConstDeclNode extends AssignableNode implements INameNode {
private final String name;
private final ByteList name;
private final INameNode constNode;

// TODO: Split this into two sub-classes so that name and constNode can be specified separately.
public ConstDeclNode(ISourcePosition position, String name, INameNode constNode, Node valueNode) {
public ConstDeclNode(ISourcePosition position, ByteList name, INameNode constNode, Node valueNode) {
super(position, valueNode, valueNode != null && valueNode.containsVariableAssignment());

this.name = name;
this.constNode = constNode;
}

@Deprecated
public ConstDeclNode(ISourcePosition position, String name, INameNode constNode, Node valueNode) {
this(position, StringSupport.stringAsByteList(name), constNode, valueNode);
}

public NodeType getNodeType() {
return NodeType.CONSTDECLNODE;
}
@@ -70,9 +77,13 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return name
*/
public String getName() {
return (name == null ? constNode.getName() : name);
return name == null ? constNode.getName() : StringSupport.byteListAsString(name);
}


public ByteList getByteName() {
return name == null ? constNode.getByteName() : name;
}

/**
* Get the full path, including the name of the new constant (in Foo::BAR it is Foo::BAR) or null.
* Your probably want to extract the left part with
20 changes: 16 additions & 4 deletions core/src/main/java/org/jruby/ast/ConstNode.java
Original file line number Diff line number Diff line change
@@ -36,18 +36,25 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* The access to a Constant.
*/
public class ConstNode extends Node implements INameNode {
private String name;
private ByteList name;

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

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

public NodeType getNodeType() {
return NodeType.CONSTNODE;
}
@@ -65,14 +72,19 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

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


@Deprecated
public void setName(String name) {
this.name = name;
this.name = StringSupport.stringAsByteList(name);
}
}
18 changes: 15 additions & 3 deletions core/src/main/java/org/jruby/ast/DAsgnNode.java
Original file line number Diff line number Diff line change
@@ -36,24 +36,31 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* An assignment to a dynamic variable (e.g. block scope local variable).
*/
public class DAsgnNode extends AssignableNode implements INameNode, IScopedNode {
// The name of the variable
private String name;
private ByteList name;

// A scoped location of this variable (high 16 bits is how many scopes down and low 16 bits
// is what index in the right scope to set the value.
private int location;

public DAsgnNode(ISourcePosition position, String name, int location, Node valueNode) {
public DAsgnNode(ISourcePosition position, ByteList name, int location, Node valueNode) {
super(position, valueNode, true);
this.name = name;
this.location = location;
}

@Deprecated
public DAsgnNode(ISourcePosition position, String name, int location, Node valueNode) {
this(position, StringSupport.stringAsByteList(name), location, valueNode);
}

public NodeType getNodeType() {
return NodeType.DASGNNODE;
}
@@ -71,6 +78,10 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

@@ -97,8 +108,9 @@ public List<Node> childNodes() {
return createList(getValueNode());
}

@Deprecated
public void setName(String name) {
this.name = name;
this.name = StringSupport.stringAsByteList(name);
}

@Override
18 changes: 15 additions & 3 deletions core/src/main/java/org/jruby/ast/DVarNode.java
Original file line number Diff line number Diff line change
@@ -36,24 +36,31 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Access a dynamic variable (e.g. block scope local variable).
*/
public class DVarNode extends Node implements INameNode, IScopedNode, SideEffectFree {
// The name of the variable
private String name;
private ByteList name;

// A scoped location of this variable (high 16 bits is how many scopes down and low 16 bits
// is what index in the right scope to set the value.
private int location;

public DVarNode(ISourcePosition position, int location, String name) {
public DVarNode(ISourcePosition position, int location, ByteList name) {
super(position, false);
this.location = location;
this.name = name;
}

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

public NodeType getNodeType() {
return NodeType.DVARNODE;
}
@@ -90,15 +97,20 @@ public int getIndex() {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

/**
* Sets the name of this variable (for refactoring support)
* @param name to set the variable to
*/
@Deprecated
public void setName(String name) {
this.name = name;
this.name = StringSupport.stringAsByteList(name);
}

public List<Node> childNodes() {
10 changes: 9 additions & 1 deletion core/src/main/java/org/jruby/ast/DefnNode.java
Original file line number Diff line number Diff line change
@@ -38,14 +38,22 @@
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,
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, name, argsNode, scope, bodyNode, endLine);
super(position, StringSupport.stringAsByteList(name), argsNode, scope, bodyNode, endLine);
}

public NodeType getNodeType() {
15 changes: 14 additions & 1 deletion core/src/main/java/org/jruby/ast/DefsNode.java
Original file line number Diff line number Diff line change
@@ -37,15 +37,28 @@
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,
StaticScope scope, Node bodyNode, int endLine) {
super(position, name, argsNode, scope, bodyNode, endLine);

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

this.receiverNode = receiverNode;
}

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

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

21 changes: 20 additions & 1 deletion core/src/main/java/org/jruby/ast/FCallNode.java
Original file line number Diff line number Diff line change
@@ -33,29 +33,44 @@
package org.jruby.ast;

import java.util.List;

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

/**
* Represents a method call with self as an implicit receiver.
*/
public class FCallNode extends Node implements INameNode, IArgumentNode, BlockAcceptingNode {
private String name;
private ByteList name;
protected Node argsNode;
protected Node iterNode;

public FCallNode(ISourcePosition position, ByteList name) {
this(position, name, null, null);
}

@Deprecated
public FCallNode(ISourcePosition position, String name) {
this(position, name, null, null);
}

@Deprecated
public FCallNode(ISourcePosition position, String name, Node argsNode, Node iterNode) {
this(position, StringSupport.stringAsByteList(name), argsNode, iterNode);
}

public FCallNode(ISourcePosition position, ByteList name, Node argsNode, Node iterNode) {
super(position, argsNode != null && argsNode.containsVariableAssignment() || iterNode != null && iterNode.containsVariableAssignment());
this.name = name;
this.argsNode = argsNode;
this.iterNode = iterNode;
setNewline();
}


public NodeType getNodeType() {
return NodeType.FCALLNODE;
}
@@ -104,6 +119,10 @@ public Node setArgsNode(Node argsNode) {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

7 changes: 7 additions & 0 deletions core/src/main/java/org/jruby/ast/FalseNode.java
Original file line number Diff line number Diff line change
@@ -36,11 +36,14 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;

/**
* Represents a false literal.
*/
public class FalseNode extends Node implements INameNode, SideEffectFree {
ByteList FALSE = new ByteList(new byte[] {'f', 'a', 'l', 's', 'e'});

public FalseNode(ISourcePosition position) {
super(position, false);
}
@@ -63,6 +66,10 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
public String getName() {
return "false";
}

public ByteList getByteName() {
return FALSE;
}

public List<Node> childNodes() {
return EMPTY_LIST;
15 changes: 13 additions & 2 deletions core/src/main/java/org/jruby/ast/GlobalAsgnNode.java
Original file line number Diff line number Diff line change
@@ -38,19 +38,26 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Represents an assignment to a global variable.
*/
public class GlobalAsgnNode extends AssignableNode implements INameNode {
private String name;
private ByteList name;

public GlobalAsgnNode(ISourcePosition position, String name, Node valueNode) {
public GlobalAsgnNode(ISourcePosition position, ByteList name, Node valueNode) {
super(position, valueNode, valueNode != null && valueNode.containsVariableAssignment());

this.name = name;
}

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

public NodeType getNodeType() {
return NodeType.GLOBALASGNNODE;
}
@@ -68,6 +75,10 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

15 changes: 13 additions & 2 deletions core/src/main/java/org/jruby/ast/GlobalVarNode.java
Original file line number Diff line number Diff line change
@@ -36,18 +36,25 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* access to a global variable.
*/
public class GlobalVarNode extends Node implements INameNode, SideEffectFree {
private String name;
private ByteList name;

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

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

public NodeType getNodeType() {
return NodeType.GLOBALVARNODE;
}
@@ -65,6 +72,10 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

18 changes: 15 additions & 3 deletions core/src/main/java/org/jruby/ast/InstAsgnNode.java
Original file line number Diff line number Diff line change
@@ -37,23 +37,30 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Represents an instance variable assignment.
*/
public class InstAsgnNode extends AssignableNode implements INameNode {
private String name;
private ByteList name;

/**
* @param name the name of the instance variable
* @param valueNode the value of the variable
**/
public InstAsgnNode(ISourcePosition position, String name, Node valueNode) {
public InstAsgnNode(ISourcePosition position, ByteList name, Node valueNode) {
super(position, valueNode, valueNode != null && valueNode.containsVariableAssignment());

this.name = name;
}

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

public NodeType getNodeType() {
return NodeType.INSTASGNNODE;
}
@@ -71,14 +78,19 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

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

@Deprecated
public void setName(String name) {
this.name = name;
this.name = StringSupport.stringAsByteList(name);
}
}
20 changes: 16 additions & 4 deletions core/src/main/java/org/jruby/ast/InstVarNode.java
Original file line number Diff line number Diff line change
@@ -37,18 +37,25 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Represents an instance variable accessor.
*/
public class InstVarNode extends Node implements INameNode, SideEffectFree {
private String name;
private ByteList name;

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

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

public NodeType getNodeType() {
return NodeType.INSTVARNODE;
}
@@ -66,14 +73,19 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

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


@Deprecated
public void setName(String name){
this.name = name;
this.name = StringSupport.stringAsByteList(name);
}
}
8 changes: 7 additions & 1 deletion core/src/main/java/org/jruby/ast/KeywordRestArgNode.java
Original file line number Diff line number Diff line change
@@ -2,15 +2,21 @@

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

/**
*
*/
public class KeywordRestArgNode extends ArgumentNode {
public KeywordRestArgNode(ISourcePosition position, ByteList name, int index) {
super(position, name, index);
}

@Deprecated
public KeywordRestArgNode(ISourcePosition position, String name, int index) {
super(position, name, index);
}

@Override
public <T> T accept(NodeVisitor<T> visitor) {
return visitor.visitKeywordRestArgNode(this);
16 changes: 12 additions & 4 deletions core/src/main/java/org/jruby/ast/LiteralNode.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.jruby.ast;

import java.util.List;


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
@@ -13,16 +17,20 @@
* subtype which is not Object.
*/
public class LiteralNode extends Node implements InvisibleNode {
private String name;
private ByteList name;

public LiteralNode(ISourcePosition position, String name) {
public LiteralNode(ISourcePosition position, ByteList name) {
super(position, false);

this.name = name;
}

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

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

/**
18 changes: 15 additions & 3 deletions core/src/main/java/org/jruby/ast/LocalAsgnNode.java
Original file line number Diff line number Diff line change
@@ -37,24 +37,31 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* An assignment to a local variable.
*/
public class LocalAsgnNode extends AssignableNode implements INameNode, IScopedNode {
// The name of the variable
private String name;
private ByteList name;

// A scoped location of this variable (high 16 bits is how many scopes down and low 16 bits
// is what index in the right scope to set the value.
private final int location;

public LocalAsgnNode(ISourcePosition position, String name, int location, Node valueNode) {
public LocalAsgnNode(ISourcePosition position, ByteList name, int location, Node valueNode) {
super(position, valueNode, true);
this.name = name;
this.location = location;
}

@Deprecated
public LocalAsgnNode(ISourcePosition position, String name, int location, Node valueNode) {
this(position, StringSupport.stringAsByteList(name), location, valueNode);
}

public NodeType getNodeType() {
return NodeType.LOCALASGNNODE;
}
@@ -71,15 +78,20 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* Name of the local assignment.
**/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

/**
* Change the name of this local assignment (for refactoring)
* @param name
*/
@Deprecated
public void setName(String name) {
this.name = name;
this.name = StringSupport.stringAsByteList(name);
}

/**
18 changes: 15 additions & 3 deletions core/src/main/java/org/jruby/ast/LocalVarNode.java
Original file line number Diff line number Diff line change
@@ -36,24 +36,31 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Access a local variable
*/
public class LocalVarNode extends Node implements INameNode, IScopedNode, SideEffectFree {
// The name of the variable
private String name;
private ByteList name;

// A scoped location of this variable (high 16 bits is how many scopes down and low 16 bits
// is what index in the right scope to set the value.
private final int location;

public LocalVarNode(ISourcePosition position, int location, String name) {
public LocalVarNode(ISourcePosition position, int location, ByteList name) {
super(position, false);
this.location = location;
this.name = name;
}

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

public NodeType getNodeType() {
return NodeType.LOCALVARNODE;
}
@@ -91,15 +98,20 @@ public int getIndex() {
* @return the name of the variable
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

/**
* Set the name of this variable (for refactoring support)
* @param name the new name
*/
@Deprecated
public void setName(String name) {
this.name = name;
this.name = StringSupport.stringAsByteList(name);
}

public List<Node> childNodes() {
12 changes: 9 additions & 3 deletions core/src/main/java/org/jruby/ast/MethodDefNode.java
Original file line number Diff line number Diff line change
@@ -34,16 +34,18 @@
import org.jruby.ast.types.INameNode;
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 String name;
protected final ByteList name;
protected final ArgsNode argsNode;
protected final StaticScope scope;
protected final Node bodyNode;
protected final int endLine;

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

assert bodyNode != null : "bodyNode must not be null";
@@ -87,6 +89,10 @@ public Node getBodyNode() {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

7 changes: 7 additions & 0 deletions core/src/main/java/org/jruby/ast/NilNode.java
Original file line number Diff line number Diff line change
@@ -36,11 +36,14 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;

/**
* represents 'nil'
*/
public class NilNode extends Node implements INameNode, SideEffectFree {
ByteList NIL = new ByteList(new byte[] {'n', 'i', 'l'});

public NilNode(ISourcePosition position) {
super(position, false);
}
@@ -63,6 +66,10 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
public String getName() {
return "nil";
}

public ByteList getByteName() {
return NIL;
}

public List<Node> childNodes() {
return EMPTY_LIST;
14 changes: 11 additions & 3 deletions core/src/main/java/org/jruby/ast/OpAsgnConstDeclNode.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
package org.jruby.ast;

import java.util.List;

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

/**
* A::B ||= 1
*/
public class OpAsgnConstDeclNode extends Node implements BinaryOperatorNode {
private Node lhs;
private String operator;
private ByteList operator;
private Node rhs;

public OpAsgnConstDeclNode(ISourcePosition position, Node lhs, String operator, Node rhs) {
public OpAsgnConstDeclNode(ISourcePosition position, Node lhs, ByteList operator, Node rhs) {
super(position, lhs.containsVariableAssignment() || rhs.containsVariableAssignment());

this.lhs = lhs;
this.operator = operator;
this.rhs = rhs;
}

@Deprecated
public OpAsgnConstDeclNode(ISourcePosition position, Node lhs, String operator, Node rhs) {
this(position, lhs, StringSupport.stringAsByteList(operator), rhs);
}

@Override
public Node getFirstNode() {
return lhs;
@@ -31,7 +39,7 @@ public Node getSecondNode() {
}

public String getOperator() {
return operator;
return StringSupport.byteListAsString(operator);
}

@Override
27 changes: 17 additions & 10 deletions core/src/main/java/org/jruby/ast/OpAsgnNode.java
Original file line number Diff line number Diff line change
@@ -35,32 +35,39 @@

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

/**
*
*/
public class OpAsgnNode extends Node {
private final Node receiverNode;
private final Node valueNode;
private final String variableName;
private final String operatorName;
private final String variableNameAsgn;
private final ByteList variableName;
private final ByteList operatorName;
private final ByteList variableNameAsgn;
private final boolean isLazy;

public OpAsgnNode(ISourcePosition position, Node receiverNode, Node valueNode, String variableName, String operatorName, boolean isLazy) {
public OpAsgnNode(ISourcePosition position, Node receiverNode, Node valueNode, ByteList variableName, ByteList operatorName, boolean isLazy) {
super(position, receiverNode.containsVariableAssignment());

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

this.receiverNode = receiverNode;
this.valueNode = valueNode;
this.variableName = variableName;
this.operatorName = operatorName;
this.variableNameAsgn = (variableName + "=").intern();
this.variableNameAsgn = ((ByteList) variableName.clone()).append('=');
this.isLazy = isLazy;
}

@Deprecated
public OpAsgnNode(ISourcePosition position, Node receiverNode, Node valueNode, String variableName, String operatorName, boolean isLazy) {
this(position, receiverNode, valueNode, StringSupport.stringAsByteList(variableName), StringSupport.stringAsByteList(operatorName), isLazy);
}

public NodeType getNodeType() {
return NodeType.OPASGNNODE;
}
@@ -78,7 +85,7 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getOperatorName() {
return operatorName;
return StringSupport.byteListAsString(operatorName);
}

/**
@@ -102,11 +109,11 @@ public Node getValueNode() {
* @return Returns a String
*/
public String getVariableName() {
return variableName;
return StringSupport.byteListAsString(variableName);
}

public String getVariableNameAsgn() {
return variableNameAsgn;
return StringSupport.byteListAsString(variableNameAsgn);
}

public List<Node> childNodes() {
18 changes: 13 additions & 5 deletions core/src/main/java/org/jruby/ast/OpElementAsgnNode.java
Original file line number Diff line number Diff line change
@@ -34,7 +34,10 @@
import java.util.List;

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

/** Represents an operator assignment to an element.
*
@@ -49,9 +52,9 @@ public class OpElementAsgnNode extends Node {
private final Node receiverNode;
private final Node argsNode;
private final Node valueNode;
private final String operatorName;
private final ByteList operatorName;

public OpElementAsgnNode(ISourcePosition position, Node receiverNode, String operatorName, Node argsNode, Node valueNode) {
public OpElementAsgnNode(ISourcePosition position, Node receiverNode, ByteList operatorName, Node argsNode, Node valueNode) {
super(position, receiverNode.containsVariableAssignment() || argsNode != null && argsNode.containsVariableAssignment() || valueNode.containsVariableAssignment());

assert receiverNode != null : "receiverNode is not null";
@@ -63,6 +66,11 @@ public OpElementAsgnNode(ISourcePosition position, Node receiverNode, String ope
this.operatorName = operatorName;
}

@Deprecated
public OpElementAsgnNode(ISourcePosition position, Node receiverNode, String operatorName, Node argsNode, Node valueNode) {
this(position, receiverNode, StringSupport.stringAsByteList(operatorName), argsNode, valueNode);
}

public NodeType getNodeType() {
return NodeType.OPELEMENTASGNNODE;
}
@@ -88,7 +96,7 @@ public Node getArgsNode() {
* @return Returns a String
*/
public String getOperatorName() {
return operatorName;
return StringSupport.byteListAsString(operatorName);
}

/**
@@ -100,11 +108,11 @@ public Node getReceiverNode() {
}

public boolean isOr() {
return getOperatorName() == "||";
return operatorName == LexingCommon.OR_OR;
}

public boolean isAnd() {
return getOperatorName() == "&&";
return operatorName == LexingCommon.AMPERSAND_AMPERSAND;
}

/**
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/ast/OptArgNode.java
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;

/**
*
@@ -66,4 +67,8 @@ public String getName() {
// FIXME: When is this not a INameNode?
return value instanceof INameNode ? ((INameNode) value).getName() : null;
}

public ByteList getByteName() {
return value instanceof INameNode ? ((INameNode) value).getByteName() : null;
}
}
7 changes: 7 additions & 0 deletions core/src/main/java/org/jruby/ast/SelfNode.java
Original file line number Diff line number Diff line change
@@ -36,11 +36,14 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;

/**
* Represents 'self' keyword
*/
public class SelfNode extends Node implements INameNode, SideEffectFree {
ByteList SELF = new ByteList(new byte[] {'s', 'e', 'l', 'f'});

public SelfNode(ISourcePosition position) {
super(position, false);
}
@@ -63,6 +66,10 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
public String getName() {
return "self";
}

public ByteList getByteName() {
return SELF;
}

public List<Node> childNodes() {
return EMPTY_LIST;
26 changes: 15 additions & 11 deletions core/src/main/java/org/jruby/ast/SymbolNode.java
Original file line number Diff line number Diff line change
@@ -41,29 +41,29 @@
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Represents a symbol (:symbol_name).
*/
public class SymbolNode extends Node implements ILiteralNode, INameNode, SideEffectFree {
private final ByteList bytes;
private final ByteList name;

// Interned ident path (e.g. [':', ident]).
@Deprecated
public SymbolNode(ISourcePosition position, String name, Encoding encoding, int cr) {
super(position, false);
this.bytes = new ByteList(name.getBytes(encoding.getCharset()), encoding);
this(position, new ByteList(name.getBytes(encoding.getCharset()), encoding));
}

// String path (e.g. [':', str_beg, str_content, str_end])
public SymbolNode(ISourcePosition position, ByteList value) {
super(position, false);
this.bytes = value;

this.name = value;
}

public boolean equals(Object other) {
return other instanceof SymbolNode &&
bytes.equals(((SymbolNode) other).bytes) &&
bytes.getEncoding() == ((SymbolNode) other).getEncoding();
name.equals(((SymbolNode) other).name) &&
name.getEncoding() == ((SymbolNode) other).getEncoding();
}

public NodeType getNodeType() {
@@ -79,18 +79,22 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getName() {
return new String(bytes.unsafeBytes(), bytes.getEncoding().getCharset());
return StringSupport.byteListAsString(name);
}

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

public ByteList getByteName() {
return name;
}

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

public ByteList getBytes() {
return bytes;
return name;
}
}
7 changes: 7 additions & 0 deletions core/src/main/java/org/jruby/ast/TrueNode.java
Original file line number Diff line number Diff line change
@@ -35,11 +35,14 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;

/**
* Represents 'true'.
*/
public class TrueNode extends Node implements INameNode, SideEffectFree {
ByteList TRUE = new ByteList(new byte[] {'t', 'r', 'u', 'e'});

public TrueNode(ISourcePosition position) {
super(position, false);
}
@@ -62,6 +65,10 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
public String getName() {
return "true";
}

public ByteList getByteName() {
return TRUE;
}

public List<Node> childNodes() {
return EMPTY_LIST;
7 changes: 6 additions & 1 deletion core/src/main/java/org/jruby/ast/UnnamedRestArgNode.java
Original file line number Diff line number Diff line change
@@ -39,6 +39,11 @@ public UnnamedRestArgNode(ISourcePosition position, String name, int index) {
}

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

@Override
public String getName() {
return isStar() ? super.getName() : null;
}
}
18 changes: 13 additions & 5 deletions core/src/main/java/org/jruby/ast/VAliasNode.java
Original file line number Diff line number Diff line change
@@ -32,22 +32,30 @@
package org.jruby.ast;

import java.util.List;

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

/**
* Represents an alias of a global variable.
*/
public class VAliasNode extends Node {
private String oldName;
private String newName;
private ByteList oldName;
private ByteList newName;

public VAliasNode(ISourcePosition position, String newName, String oldName) {
public VAliasNode(ISourcePosition position, ByteList newName, ByteList oldName) {
super(position, false);
this.oldName = oldName;
this.newName = newName;
}

@Deprecated
public VAliasNode(ISourcePosition position, String newName, String oldName) {
this(position, StringSupport.stringAsByteList(newName), StringSupport.stringAsByteList(oldName));
}

public NodeType getNodeType() {
return NodeType.VALIASNODE;
}
@@ -65,15 +73,15 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getNewName() {
return newName;
return StringSupport.byteListAsString(newName);
}

/**
* Gets the oldName.
* @return Returns a String
*/
public String getOldName() {
return oldName;
return StringSupport.byteListAsString(oldName);
}

public List<Node> childNodes() {
16 changes: 14 additions & 2 deletions core/src/main/java/org/jruby/ast/VCallNode.java
Original file line number Diff line number Diff line change
@@ -33,24 +33,32 @@
package org.jruby.ast;

import java.util.List;

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

/**
* RubyMethod call without any arguments
*
*/
public class VCallNode extends Node implements INameNode {
private String name;
private ByteList name;

public VCallNode(ISourcePosition position, String name) {
public VCallNode(ISourcePosition position, ByteList name) {
super(position, false);

this.name = name;
setNewline();
}

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

public NodeType getNodeType() {
return NodeType.VCALLNODE;
}
@@ -68,6 +76,10 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return Returns a String
*/
public String getName() {
return StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
return name;
}

3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/ast/types/INameNode.java
Original file line number Diff line number Diff line change
@@ -27,6 +27,9 @@
***** END LICENSE BLOCK *****/
package org.jruby.ast.types;

import org.jruby.util.ByteList;

public interface INameNode {
public String getName();
public ByteList getByteName();
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -2081,15 +2081,15 @@ public Operand buildDefn(MethodDefNode node) { // Instance method
IRMethod method = defineNewMethod(node, true);
addInstr(new DefineInstanceMethodInstr(method));
// FIXME: Method name should save encoding
return new Symbol(method.getName(), ASCIIEncoding.INSTANCE);
return new Symbol(method.getName(), USASCIIEncoding.INSTANCE);
}

public Operand buildDefs(DefsNode node) { // Class method
Operand container = build(node.getReceiverNode());
IRMethod method = defineNewMethod(node, false);
addInstr(new DefineClassMethodInstr(container, method));
// FIXME: Method name should save encoding
return new Symbol(method.getName(), ASCIIEncoding.INSTANCE);
return new Symbol(method.getName(), USASCIIEncoding.INSTANCE);
}

protected LocalVariable getArgVariable(String name, int depth) {
99 changes: 96 additions & 3 deletions core/src/main/java/org/jruby/lexer/LexingCommon.java
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ public LexingCommon(LexerSource src) {
public boolean commandStart;
protected StackState conditionState = new StackState();
protected StackState cmdArgumentState = new StackState();
private String current_arg;
private ByteList current_arg;
private Encoding current_enc;
protected boolean __end__seen = false;
public boolean eofp = false;
@@ -79,6 +79,62 @@ public LexingCommon(LexerSource src) {
public ISourcePosition tokline;
public int tokp = 0; // Where last token started
protected Object yaccValue; // Value of last token which had a value associated with it.
protected ByteList identifier = null; // until we get rid of String + ByteList duality we have this as extra field.

public final ByteList BACKTICK = new ByteList(new byte[] {'`'}, USASCII_ENCODING);
public final ByteList EQ_EQ_EQ = new ByteList(new byte[] {'=', '=', '='}, USASCII_ENCODING);
public final ByteList EQ_EQ = new ByteList(new byte[] {'=', '='}, USASCII_ENCODING);
protected ByteList EQ_TILDE = new ByteList(new byte[] {'=', '~'}, USASCII_ENCODING);
protected ByteList EQ_GT = new ByteList(new byte[] {'=', '>'}, USASCII_ENCODING);
protected ByteList EQ = new ByteList(new byte[] {'='}, USASCII_ENCODING);
public static final ByteList AMPERSAND_AMPERSAND = new ByteList(new byte[] {'&', '&'}, USASCIIEncoding.INSTANCE);
protected ByteList AMPERSAND = new ByteList(new byte[] {'&'}, USASCII_ENCODING);
public ByteList AMPERSAND_DOT = new ByteList(new byte[] {'&', '.'}, USASCII_ENCODING);
public final ByteList BANG = new ByteList(new byte[] {'!'}, USASCII_ENCODING);
protected ByteList BANG_EQ = new ByteList(new byte[] {'!', '='}, USASCII_ENCODING);
protected ByteList BANG_TILDE = new ByteList(new byte[] {'!', '~'}, USASCII_ENCODING);
protected ByteList CARET = new ByteList(new byte[] {'^'}, USASCII_ENCODING);
protected ByteList COLON_COLON = new ByteList(new byte[] {':', ':'}, USASCII_ENCODING);
protected ByteList COLON = new ByteList(new byte[] {':'}, USASCII_ENCODING);
protected ByteList COMMA = new ByteList(new byte[] {','}, USASCII_ENCODING);
protected ByteList DOT_DOT_DOT = new ByteList(new byte[] {'.', '.', '.'}, USASCII_ENCODING);
protected ByteList DOT_DOT = new ByteList(new byte[] {'.', '.'}, USASCII_ENCODING);
public ByteList DOT = new ByteList(new byte[] {'.'}, USASCII_ENCODING);
protected ByteList GT_EQ = new ByteList(new byte[] {'>', '='}, USASCII_ENCODING);
protected ByteList GT_GT = new ByteList(new byte[] {'>', '>'}, USASCII_ENCODING);
protected ByteList GT = new ByteList(new byte[] {'>'}, USASCII_ENCODING);
protected ByteList LBRACKET_RBRACKET_EQ = new ByteList(new byte[] {'[', ']', '='}, USASCII_ENCODING);
public static ByteList LBRACKET_RBRACKET = new ByteList(new byte[] {'[', ']'}, USASCIIEncoding.INSTANCE);
protected ByteList LBRACKET = new ByteList(new byte[] {'['}, USASCII_ENCODING);
protected ByteList LCURLY = new ByteList(new byte[] {'{'}, USASCII_ENCODING);
protected ByteList LT_EQ_RT = new ByteList(new byte[] {'<', '=', '>'}, USASCII_ENCODING);
protected ByteList LT_EQ = new ByteList(new byte[] {'<', '='}, USASCII_ENCODING);
protected ByteList LT_LT = new ByteList(new byte[] {'<', '<'}, USASCII_ENCODING);
protected ByteList LT = new ByteList(new byte[] {'<'}, USASCII_ENCODING);
protected ByteList MINUS_AT = new ByteList(new byte[] {'-', '@'}, USASCII_ENCODING);
protected ByteList MINUS = new ByteList(new byte[] {'-'}, USASCII_ENCODING);
protected ByteList MINUS_GT = new ByteList(new byte[] {'-', '>'}, USASCII_ENCODING);
protected ByteList PERCENT = new ByteList(new byte[] {'%'}, USASCII_ENCODING);
public static final ByteList OR_OR = new ByteList(new byte[] {'|', '|'}, USASCIIEncoding.INSTANCE);
protected ByteList OR = new ByteList(new byte[] {'|'}, USASCII_ENCODING);
protected ByteList PLUS_AT = new ByteList(new byte[] {'+', '@'}, USASCII_ENCODING);
protected ByteList PLUS = new ByteList(new byte[] {'+'}, USASCII_ENCODING);
protected ByteList QUESTION = new ByteList(new byte[] {'?'}, USASCII_ENCODING);
protected ByteList RBRACKET = new ByteList(new byte[] {']'}, USASCII_ENCODING);
protected ByteList RCURLY = new ByteList(new byte[] {'}'}, USASCII_ENCODING);
protected ByteList RPAREN = new ByteList(new byte[] {')'}, USASCII_ENCODING);
protected ByteList Q = new ByteList(new byte[] {'\''}, USASCII_ENCODING);
protected ByteList SLASH = new ByteList(new byte[] {'/'}, USASCII_ENCODING);
protected ByteList STAR = new ByteList(new byte[] {'*'}, USASCII_ENCODING);
protected ByteList STAR_STAR = new ByteList(new byte[] {'*', '*'}, USASCII_ENCODING);
protected ByteList TILDE = new ByteList(new byte[] {'~'}, USASCII_ENCODING);
protected ByteList QQ = new ByteList(new byte[] {'"'}, USASCII_ENCODING);
protected ByteList SEMICOLON = new ByteList(new byte[] {';'}, USASCII_ENCODING);
protected ByteList BACKSLASH = new ByteList(new byte[] {'\\'}, USASCII_ENCODING);
public static final ByteList CALL = new ByteList(new byte[] {'c', 'a', 'l', 'l'}, USASCIIEncoding.INSTANCE);
public static final ByteList DOLLAR_BANG = new ByteList(new byte[] {'$', '!'}, USASCIIEncoding.INSTANCE);
public static final ByteList DOLLAR_UNDERSCORE = new ByteList(new byte[] {'$', '_'}, USASCIIEncoding.INSTANCE);
public static final ByteList DOLLAR_DOT = new ByteList(new byte[] {'$', '_'}, USASCIIEncoding.INSTANCE);

public int column() {
return tokp - lex_pbeg;
@@ -111,7 +167,14 @@ public String createTokenString(int start) {
return createAsEncodedString(lexb.getUnsafeBytes(), lexb.begin() + start, lex_p - start, getEncoding());
}

public ByteList getIdentifier() {
return identifier;
}

public String createAsEncodedString(byte[] bytes, int start, int length, Encoding encoding) {
// We copy because the source is typically an entire source line (it will appear leakish?).
identifier = new ByteList(bytes, start, length, encoding, true);

// FIXME: We should be able to move some faster non-exception cache using Encoding.isDefined
try {
Charset charset = getEncoding().getCharset();
@@ -170,7 +233,7 @@ public StackState getConditionState() {
return conditionState;
}

public String getCurrentArg() {
public ByteList getCurrentArg() {
return current_arg;
}

@@ -414,7 +477,7 @@ protected char scanOct(int count) throws IOException {
return value;
}

public void setCurrentArg(String current_arg) {
public void setCurrentArg(ByteList current_arg) {
this.current_arg = current_arg;
}

@@ -607,6 +670,36 @@ public boolean update_heredoc_indent(int c) {
return false;
}

public void validateFormalIdentifier(ByteList identifier) {
char first = identifier.charAt(0);

if (Character.isUpperCase(first)) {
compile_error("formal argument cannot be a constant");
}

switch(first) {
case '@':
if (identifier.charAt(1) == '@') {
compile_error("formal argument cannot be a class variable");
} else {
compile_error("formal argument cannot be an instance variable");
}
break;
case '$':
compile_error("formal argument cannot be a global variable");
break;
default:
// This mechanism feels a tad dicey but at this point we are dealing with a valid
// method name at least so we should not need to check the entire string...
char last = identifier.charAt(identifier.length() - 1);

if (last == '=' || last == '?' || last == '!') {
compile_error("formal argument must be local variable");
}
}
}

@Deprecated
public void validateFormalIdentifier(String identifier) {
char first = identifier.charAt(0);

260 changes: 132 additions & 128 deletions core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java

Large diffs are not rendered by default.

215 changes: 198 additions & 17 deletions core/src/main/java/org/jruby/parser/ParserSupport.java

Large diffs are not rendered by default.

779 changes: 552 additions & 227 deletions core/src/main/java/org/jruby/parser/RubyParser.java

Large diffs are not rendered by default.

683 changes: 419 additions & 264 deletions core/src/main/java/org/jruby/parser/RubyParser.y

Large diffs are not rendered by default.

115 changes: 79 additions & 36 deletions core/src/main/java/org/jruby/parser/StaticScope.java
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
import java.lang.invoke.MethodHandles;
import java.util.Arrays;

import org.jcodings.specific.USASCIIEncoding;
import org.jruby.RubyModule;
import org.jruby.RubyObject;
import org.jruby.ast.AssignableNode;
@@ -53,6 +54,8 @@
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.scope.DynamicScopeGenerator;
import org.jruby.runtime.scope.ManyVarsDynamicScope;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* StaticScope represents lexical scoping of variables and module/class constants.
@@ -81,7 +84,7 @@ public class StaticScope implements Serializable {
private StaticScope previousCRefScope = null;

// Our name holder (offsets are assigned as variables are added)
private String[] variableNames;
private ByteList[] variableNames;

private int variableNamesLength;

@@ -98,7 +101,7 @@ public class StaticScope implements Serializable {

protected IRScopeType scopeType;

private static final String[] NO_NAMES = new String[0];
private static final ByteList[] NO_NAMES = new ByteList[0];

private Type type;
private boolean isBlockOrEval;
@@ -152,9 +155,8 @@ protected StaticScope(Type type, StaticScope enclosingScope) {
* @param enclosingScope the lexically containing scope.
* @param names The list of interned String variable names.
*/
protected StaticScope(Type type, StaticScope enclosingScope, String[] names, int firstKeywordIndex) {
protected StaticScope(Type type, StaticScope enclosingScope, ByteList[] names, int firstKeywordIndex) {
assert names != null : "names is not null";
assert namesAreInterned(names);

this.enclosingScope = enclosingScope;
this.variableNames = names;
@@ -166,7 +168,7 @@ protected StaticScope(Type type, StaticScope enclosingScope, String[] names, int
this.firstKeywordIndex = firstKeywordIndex;
}

protected StaticScope(Type type, StaticScope enclosingScope, String[] names) {
protected StaticScope(Type type, StaticScope enclosingScope, ByteList[] names) {
this(type, enclosingScope, names, -1);
}

@@ -217,29 +219,14 @@ public void setIRScope(IRScope irScope) {
this.scopeType = irScope.getScopeType();
}

/**
* Check that all strings in the given array are the interned versions.
*
* @param names The array of strings
* @return true if they are all interned, false otherwise
*/
private static boolean namesAreInterned(String[] names) {
for (String name : names) {
// Note that this object equality check is intentional, to ensure
// the string and its interned version are the same object.
if (name != name.intern()) return false;
}
return true;
}

/**
* Add a new variable to this (current) scope unless it is already defined in the
* current scope.
*
* @param name of new variable
* @return index of variable
*/
public int addVariableThisScope(String name) {
public int addVariableThisScope(ByteList name) {
int slot = exists(name);

if (slot >= 0) return slot;
@@ -254,6 +241,11 @@ public int addVariableThisScope(String name) {
return variableNames.length - 1;
}

@Deprecated
public int addVariableThisScope(String stringName) {
return addVariableThisScope(new ByteList(stringName.getBytes(), USASCIIEncoding.INSTANCE));
}

/**
* Add a new named capture variable to this (current) scope.
*
@@ -275,7 +267,7 @@ public int addNamedCaptureVariable(String name) {
* @param name of new variable
* @return index+depth merged location of scope
*/
public int addVariable(String name) {
public int addVariable(ByteList name) {
int slot = isDefined(name);

if (slot >= 0) return slot;
@@ -290,7 +282,21 @@ public int addVariable(String name) {
return variableNames.length - 1;
}

@Deprecated
public int addVariable(String name) {
return addVariable(new ByteList(name.getBytes(), USASCIIEncoding.INSTANCE));
}

@Deprecated
public String[] getVariables() {
String[] newVars = new String[variableNames.length];
for (int i = 0; i < variableNames.length; i++) {
newVars[i] = variableNames[i].toString();
}
return newVars;
}

public ByteList[] getByteVariables() {
return variableNames;
}

@@ -300,12 +306,11 @@ public int getNumberOfVariables() {

public void setVariables(String[] names) {
assert names != null : "names is not null";
assert namesAreInterned(names);

// Clear constructor since we are changing names
constructor = null;

variableNames = new String[names.length];
variableNames = new ByteList[names.length];
variableNamesLength = names.length;
System.arraycopy(names, 0, variableNames, 0, names.length);
}
@@ -371,13 +376,18 @@ public StaticScope getEnclosingScope() {
* @param name of the variable to find
* @return index of variable or -1 if it does not exist
*/
public int exists(String name) {
public int exists(ByteList name) {
return findVariableName(name);
}

private int findVariableName(String name) {
@Deprecated
public int exists(String name) {
return findVariableName(new ByteList(name.getBytes(), USASCIIEncoding.INSTANCE));
}

private int findVariableName(ByteList name) {
for (int i = 0; i < variableNames.length; i++) {
if (name == variableNames[i]) return i;
if (name.equal(variableNames[i])) return i;
}
return -1;
}
@@ -389,6 +399,11 @@ private int findVariableName(String name) {
* @return a location where the left-most 16 bits of number of scopes down it is and the
* right-most 16 bits represents its index in that scope
*/
public int isDefined(ByteList name) {
return isDefined(name, 0);
}

@Deprecated
public int isDefined(String name) {
return isDefined(name, 0);
}
@@ -401,6 +416,11 @@ public int isDefined(String name) {
* @param value
* @return
*/
public AssignableNode assign(ISourcePosition position, ByteList name, Node value) {
return assign(position, name, value, this, 0);
}

@Deprecated
public AssignableNode assign(ISourcePosition position, String name, Node value) {
return assign(position, name, value, this, 0);
}
@@ -414,7 +434,7 @@ public AssignableNode assign(ISourcePosition position, String name, Node value)
* @param value
* @return
*/
public AssignableNode assignKeyword(ISourcePosition position, String name, Node value) {
public AssignableNode assignKeyword(ISourcePosition position, ByteList name, Node value) {
AssignableNode assignment = assign(position, name, value, this, 0);

// register first keyword index encountered
@@ -423,6 +443,11 @@ public AssignableNode assignKeyword(ISourcePosition position, String name, Node
return assignment;
}

@Deprecated
public AssignableNode assignKeyword(ISourcePosition position, String name, Node value) {
return assignKeyword(position, StringSupport.stringAsByteList(name), value);
}

public boolean keywordExists(String name) {
int slot = exists(name);

@@ -451,7 +476,7 @@ public String[] getAllNamesInScope() {
return names;
}

public int isDefined(String name, int depth) {
public int isDefined(ByteList name, int depth) {
if (isBlockOrEval) {
int slot = exists(name);
if (slot >= 0) return (depth << 16) | slot;
@@ -462,13 +487,22 @@ public int isDefined(String name, int depth) {
}
}

public AssignableNode addAssign(ISourcePosition position, String name, Node value) {
public int isDefined(String name, int depth) {
return isDefined(new ByteList(name.getBytes(), USASCIIEncoding.INSTANCE), depth);
}

public AssignableNode addAssign(ISourcePosition position, ByteList name, Node value) {
int slot = addVariable(name);
// No bit math to store level since we know level is zero for this case
return new DAsgnNode(position, name, slot, value);
}

public AssignableNode assign(ISourcePosition position, String name, Node value,
@Deprecated
public AssignableNode addAssign(ISourcePosition position, String name, Node value) {
return addAssign(position, new ByteList(name.getBytes(), USASCIIEncoding.INSTANCE), value);
}

public AssignableNode assign(ISourcePosition position, ByteList name, Node value,
StaticScope topScope, int depth) {
int slot = exists(name);

@@ -490,7 +524,13 @@ public AssignableNode assign(ISourcePosition position, String name, Node value,
: topScope.addAssign(position, name, value);
}

public Node declare(ISourcePosition position, String name, int depth) {
@Deprecated
public AssignableNode assign(ISourcePosition position, String name, Node value,
StaticScope topScope, int depth) {
return assign(position, new ByteList(name.getBytes(), USASCIIEncoding.INSTANCE), value, topScope, depth);
}

public Node declare(ISourcePosition position, ByteList name, int depth) {
int slot = exists(name);

if (slot >= 0) {
@@ -507,10 +547,14 @@ public Node declare(ISourcePosition position, String name, int depth) {
* @param name of the variable to be created is named
* @return a DVarNode or LocalVarNode
*/
public Node declare(ISourcePosition position, String name) {
public Node declare(ISourcePosition position, ByteList name) {
return declare(position, name, 0);
}

@Deprecated
public Node declare(ISourcePosition position, String name) {
return declare(position, new ByteList(name.getBytes(), USASCIIEncoding.INSTANCE));
}
/**
* Gets the Local Scope relative to the current Scope. For LocalScopes this will be itself.
* Blocks will contain the LocalScope it contains.
@@ -613,9 +657,8 @@ public long getCommandArgumentStack() {
return commandArgumentStack;
}

private void growVariableNames(String name) {
assert name == name.intern();
String[] newVariableNames = new String[variableNames.length + 1];
private void growVariableNames(ByteList name) {
ByteList[] newVariableNames = new ByteList[variableNames.length + 1];
System.arraycopy(variableNames, 0, newVariableNames, 0, variableNames.length);
variableNames = newVariableNames;
variableNamesLength = newVariableNames.length;
32 changes: 27 additions & 5 deletions core/src/main/java/org/jruby/parser/StaticScopeFactory.java
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@


import org.jruby.Ruby;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Gives instances of static scopes based on compile mode.
@@ -22,18 +24,28 @@ public StaticScope newBlockScope(StaticScope parent) {
return new StaticScope(StaticScope.Type.BLOCK, parent);
}

public StaticScope newBlockScope(StaticScope parent, String[] names) {
public StaticScope newBlockScope(StaticScope parent, ByteList[] names) {
return new StaticScope(StaticScope.Type.BLOCK, parent, names);
}

@Deprecated
public StaticScope newBlockScope(StaticScope parent, String[] names) {
return new StaticScope(StaticScope.Type.BLOCK, parent, StringSupport.stringsAsByteLists(names));
}

public StaticScope newEvalScope(StaticScope parent) {
return new StaticScope(StaticScope.Type.EVAL, parent);
}

public StaticScope newEvalScope(StaticScope parent, String[] names) {
public StaticScope newEvalScope(StaticScope parent, ByteList[] names) {
return new StaticScope(StaticScope.Type.EVAL, parent, names);
}

@Deprecated
public StaticScope newEvalScope(StaticScope parent, String[] names) {
return new StaticScope(StaticScope.Type.EVAL, parent, StringSupport.stringsAsByteLists(names));
}

public StaticScope newLocalScope(StaticScope parent, String file) {
return new StaticScope(StaticScope.Type.LOCAL, parent, file);
}
@@ -42,10 +54,15 @@ public StaticScope newLocalScope(StaticScope parent) {
return new StaticScope(StaticScope.Type.LOCAL, parent);
}

public StaticScope newLocalScope(StaticScope parent, String[] names) {
public StaticScope newLocalScope(StaticScope parent, ByteList[] names) {
return new StaticScope(StaticScope.Type.LOCAL, parent, names);
}

@Deprecated
public StaticScope newLocalScope(StaticScope parent, String[] names) {
return new StaticScope(StaticScope.Type.LOCAL, parent, StringSupport.stringsAsByteLists(names));
}

// We only call these from inside IR impl (IR is all or nothing)
public static StaticScope newIRBlockScope(StaticScope parent) {
return new StaticScope(StaticScope.Type.BLOCK, parent);
@@ -56,18 +73,23 @@ public static StaticScope newStaticScope(StaticScope parent, StaticScope.Type ty
if(names == null) {
return new StaticScope(type, parent);
} else {
return new StaticScope(type, parent, names);
return new StaticScope(type, parent, StringSupport.stringsAsByteLists(names));
}
}

public static StaticScope newStaticScope(StaticScope parent, StaticScope.Type type, String[] names, int keywordArgIndex) {
public static StaticScope newStaticScope(StaticScope parent, StaticScope.Type type, ByteList[] names, int keywordArgIndex) {
if(names == null) {
return new StaticScope(type, parent);
} else {
return new StaticScope(type, parent, names, keywordArgIndex);
}
}

@Deprecated
public static StaticScope newStaticScope(StaticScope parent, StaticScope.Type type, String[] names, int keywordArgIndex) {
return newStaticScope(parent, type, StringSupport.stringsAsByteLists(names), keywordArgIndex);
}


public StaticScope getDummyScope() {
return dummyScope;
40 changes: 34 additions & 6 deletions core/src/main/java/org/jruby/parser/YyTables.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
/*
***** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2013-2017 The JRuby Team (jruby@jruby.org)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/
package org.jruby.parser;

public class YyTables {
@@ -27,13 +55,13 @@ private static final short[] yyTable1() {

305, 378, 308, 88, 88, 134, 134, 254, 257, 324,
250, 250, 250, 228, 427, 276, 250, 250, 230, 465,
250, 418, 715, 420, 107, 83, 83, 260, 214, 635,
250, 418, 715, 420, 107, 83, 83, 260, 215, 635,
642, 352, 714, 228, 487, 714, 302, 307, 230, 354,
702, 215, 215, 292, 292, 440, 88, 292, 133, 133,
702, 214, 214, 292, 292, 440, 88, 292, 133, 133,
350, 696, 250, 677, 631, 643, 675, 629, 133, 648,
585, 715, 215, 288, 288, 661, 631, 288, 639, 642,
585, 715, 214, 288, 288, 661, 631, 288, 639, 642,
387, 644, 691, 806, 360, 331, 335, 256, 417, 642,
526, 291, 291, 642, 528, 291, 705, 215, 578, 826,
526, 291, 291, 642, 528, 291, 705, 214, 578, 826,
739, 631, 435, 133, 8, 676, 724, 630, 642, 642,
350, 301, 870, 835, 8, 304, 576, 760, 762, 631,
1031, 639, 562, 330, 17, 570, 642, 431, 642, 387,
@@ -78,7 +106,7 @@ private static final short[] yyTable1() {
92, 92, 135, 135, 74, 250, 106, 88, 288, 228,
640, 713, 277, 722, 230, 576, 429, 1005, 88, 310,
982, 303, 288, 272, 441, 641, 272, 452, 73, 83,
81, 596, 562, 697, 250, 570, 350, 455, 215, 274,
81, 596, 562, 697, 250, 570, 350, 455, 214, 274,
91, 641, 274, 92, 640, 380, 75, 351, 547, 601,
732, 1050, 1052, 1053, 1054, 641, 462, 373, 106, 106,
106, 106, 106, 106, 106, 596, 536, 537, 378, 640,
@@ -96,7 +124,7 @@ private static final short[] yyTable1() {
84, 88, 82, 106, 803, 106, 1000, 642, 747, 228,
76, 676, 1002, 813, 230, 493, 106, 564, 565, 386,
133, 77, 95, 95, 812, 836, 1012, 103, 506, 250,
785, 782, 106, 510, 278, 530, 511, 215, 215, 788,
785, 782, 106, 510, 278, 530, 511, 214, 214, 788,
906, 558, 110, 642, 788, 860, 559, 515, 319, 88,
536, 537, 92, 82, 350, 521, 642, 539, 443, 443,
527, 102, 544, 529, 443, 95, 840, 860, 535, 888,
39 changes: 39 additions & 0 deletions core/src/main/java/org/jruby/util/StringSupport.java
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
import org.jcodings.ascii.AsciiTables;
import org.jcodings.constants.CharacterType;
import org.jcodings.specific.ASCIIEncoding;
import org.jcodings.specific.USASCIIEncoding;
import org.jcodings.specific.UTF8Encoding;
import org.jcodings.util.IntHash;
import org.joni.Matcher;
@@ -2430,4 +2431,42 @@ public static boolean multiByteUpcase(Encoding enc, byte[] bytes, int s, int end
public static int encCoderangeClean(int cr) {
return (cr ^ (cr >> 1)) & CR_7BIT;
}


/**
* This is a far from perfect method in that it will totally choke on anything not UTF-8.
* However virtually nothing which was represented internally as a String would work with
* any String which was not UTF-8 (and in some cases 7-bit ASCII).
*
* Note: Do not use unless you are core developer or at least acknowledge the issues with
* this method.
*/
@Deprecated
public static ByteList stringAsByteList(String string) {
if (string == null) return null; // For UnnamedRestArgNode
return ByteList.create(string);
}

/**
* This is a far from perfect method in that it will totally choke on anything not UTF-8.
* However virtually nothing which was represented internally as a String would work with
* any String which was not UTF-8 (and in some cases 7-bit ASCII).
*
* Note: Do not use unless you are core developer or at least acknowledge the issues with
* this method.
*/
@Deprecated
public static ByteList[] stringsAsByteLists(String[] strings) {
ByteList[] newList = new ByteList[strings.length];

for (int i = 0; i < strings.length; i++) {
newList[i] = stringAsByteList(strings[i]);
}

return newList;
}

public static String byteListAsString(ByteList bytes) {
return new String(bytes.unsafeBytes(), bytes.begin(), bytes.realSize(), bytes.getEncoding().getCharset());
}
}

2 comments on commit c4e7631

@lopex
Copy link
Contributor

@lopex lopex commented on c4e7631 May 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enebo: Shouldn't be false / true / nil name ByteLists static ?

@enebo
Copy link
Member Author

@enebo enebo commented on c4e7631 May 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lopex yeah fixed them all (I think).

Please sign in to comment.