Skip to content

Commit

Permalink
[Truffle] Mass handling of operations on String subclasses.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Mar 6, 2015
1 parent 96f3641 commit c25d417
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 32 deletions.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/string/byteslice_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/capitalize_tags.txt
@@ -1,2 +1 @@
fails:String#capitalize is locale insensitive (only upcases a-z and only downcases A-Z)
fails:String#capitalize returns subclass instances when called on a subclass
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/downcase_tags.txt
@@ -1,2 +1 @@
fails:String#downcase is locale insensitive (only replaces A-Z)
fails:String#downcase returns a subclass instance for subclasses
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/dump_tags.txt
@@ -1,2 +1 @@
fails:String#dump returns a subclass instance
fails:String#dump includes .force_encoding(name) if the encoding isn't ASCII compatible
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/each_line_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/string/element_reference_tags.txt
@@ -1,5 +1,3 @@
fails:String#[] with index, length returns subclass instances
fails:String#[] with Range returns subclass instances
fails:String#[] with Range calls to_int on range arguments
fails:String#[] with Range works with Range subclasses
fails:String#[] with Regexp returns subclass instances
Expand Down
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/gsub_tags.txt
Expand Up @@ -9,4 +9,3 @@ fails:String#gsub! with pattern and block uses the compatible encoding if they a
fails:String#gsub! with pattern and block replaces the incompatible part properly even if the encodings are not compatible
fails:String#gsub with pattern and replacement respects $KCODE when the pattern collapses
fails:String#gsub with pattern and replacement handles pattern collapse without $KCODE
fails:String#gsub with pattern and replacement returns subclass instances when called on a subclass
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/lines_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/core/string/slice_tags.txt
@@ -1,5 +1,3 @@
fails:String#slice with index, length returns subclass instances
fails:String#slice with Range returns subclass instances
fails:String#slice with Range calls to_int on range arguments
fails:String#slice with Range works with Range subclasses
fails:String#slice with Regexp returns subclass instances
Expand All @@ -14,7 +12,6 @@ fails:String#slice! with index, length always taints resulting strings when self
fails:String#slice! with index, length calls to_int on idx and length
fails:String#slice! with index, length returns subclass instances
fails:String#slice! with index, length returns the substring given by the character offsets
fails:String#slice! Range returns subclass instances
fails:String#slice! Range calls to_int on range arguments
fails:String#slice! Range works with Range subclasses
fails:String#slice! Range returns the substring given by the character offsets of the range
Expand Down
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/sub_tags.txt
@@ -1,5 +1,4 @@
fails:String#sub with pattern, replacement treats \+ as an empty string if there was no captures
fails:String#sub with pattern, replacement returns subclass instances when called on a subclass
fails:String#sub with pattern and block sets $~ for access from the block
fails:String#sub! with pattern and block sets $~ for access from the block
fails:String#sub! with pattern and block raises a RuntimeError if the string is modified while substituting
Expand Down
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/succ_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/swapcase_tags.txt
@@ -1,3 +1,2 @@
fails:String#swapcase is locale insensitive (only upcases a-z and only downcases A-Z)
fails:String#swapcase returns subclass instances when called on a subclass
fails:String#swapcase! returns nil if no modifications were made
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/upcase_tags.txt
@@ -1,3 +1,2 @@
fails:String#upcase is locale insensitive (only replaces a-z)
fails:String#upcase returns a subclass instance for subclasses
fails:String#upcase! returns nil if no modifications were made
22 changes: 12 additions & 10 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
Expand Up @@ -305,7 +305,7 @@ public Object getIndex(RubyString string, int index, @SuppressWarnings("unused")
outOfBounds.enter();
return getContext().getCoreLibrary().getNilObject();
} else {
return getContext().makeString(bytes.charAt(normalizedIndex), string.getByteList().getEncoding());
return getContext().makeString(string.getLogicalClass(), bytes.charAt(normalizedIndex), string.getByteList().getEncoding());
}
}

Expand Down Expand Up @@ -337,7 +337,9 @@ public Object slice(RubyString string, RubyRange.IntegerFixnumRange range, @Supp
return getContext().makeString("");
}

return getContext().makeString(javaString.substring(begin, excludingEnd), string.getByteList().getEncoding());
return getContext().makeString(string.getLogicalClass(),
javaString.substring(begin, excludingEnd),
string.getByteList().getEncoding());
}
}

Expand All @@ -356,7 +358,7 @@ public Object slice(RubyString string, int start, int length) {
final ByteList byteList = new ByteList(bytes, begin, end - begin);
byteList.setEncoding(string.getByteList().getEncoding());

return getContext().makeString(byteList);
return getContext().makeString(string.getLogicalClass(), byteList);
}
}

Expand Down Expand Up @@ -749,7 +751,7 @@ public RubyString downcase(RubyString string) {
notDesignedForCompilation();
ByteList newByteList = StringNodesHelper.downcase(string);

return string.getContext().makeString(newByteList);
return string.getContext().makeString(string.getLogicalClass(), newByteList);
}
}

Expand Down Expand Up @@ -1345,7 +1347,7 @@ public RubyString swapcase(RubyString string) {
notDesignedForCompilation();

ByteList byteList = StringNodesHelper.swapcase(string);
return getContext().makeString(byteList);
return getContext().makeString(string.getLogicalClass(), byteList);
}
}

Expand Down Expand Up @@ -1590,7 +1592,7 @@ private RubyArray splitHelper(RubyString string, String sep) {
final Object[] objects = new Object[components.length];

for (int n = 0; n < objects.length; n++) {
objects[n] = getContext().makeString(components[n]);
objects[n] = getContext().makeString(string.getLogicalClass(), components[n]);
}

return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), objects);
Expand All @@ -1613,9 +1615,9 @@ public RubyString succ(RubyString string) {
notDesignedForCompilation();

if (string.length() > 0) {
return getContext().makeString(StringSupport.succCommon(string.getBytes()));
return getContext().makeString(string.getLogicalClass(), StringSupport.succCommon(string.getBytes()));
} else {
return getContext().makeString("");
return getContext().makeString(string.getLogicalClass(), "");
}
}
}
Expand Down Expand Up @@ -1825,7 +1827,7 @@ public RubyString upcase(RubyString string) {
notDesignedForCompilation();
final ByteList byteListString = StringNodesHelper.upcase(string);

return string.getContext().makeString(byteListString);
return string.getContext().makeString(string.getLogicalClass(), byteListString);
}

}
Expand Down Expand Up @@ -1921,7 +1923,7 @@ public RubyString capitalize(RubyString string) {
return string;
} else {
final ByteList byteListString = StringNodesHelper.capitalize(string);
return string.getContext().makeString(byteListString);
return string.getContext().makeString(string.getLogicalClass(), byteListString);
}
}

Expand Down
Expand Up @@ -120,7 +120,7 @@ public Object stringByteSubstring(RubyString string, int index, int length) {
}

final byte[] copiedBytes = Arrays.copyOfRange(bytes.getUnsafeBytes(), normalizedIndex, rangeEnd);
final RubyString result = new RubyString(getContext().getCoreLibrary().getStringClass(), new ByteList(copiedBytes, string.getBytes().getEncoding()));
final RubyString result = getContext().makeString(string.getLogicalClass(), new ByteList(copiedBytes, string.getBytes().getEncoding()));

return taintResultNode.maybeTaint(string, result);
}
Expand Down
22 changes: 19 additions & 3 deletions truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Expand Up @@ -274,11 +274,19 @@ public void shutdown() {
}

public RubyString makeString(String string) {
return RubyString.fromJavaString(coreLibrary.getStringClass(), string);
return makeString(coreLibrary.getStringClass(), string);
}

public RubyString makeString(RubyClass stringClass, String string) {
return RubyString.fromJavaString(stringClass, string);
}

public RubyString makeString(String string, Encoding encoding) {
return RubyString.fromJavaString(coreLibrary.getStringClass(), string, encoding);
return makeString(coreLibrary.getStringClass(), string, encoding);
}

public RubyString makeString(RubyClass stringClass, String string, Encoding encoding) {
return RubyString.fromJavaString(stringClass, string, encoding);
}

public RubyString makeString(char string) {
Expand All @@ -289,8 +297,16 @@ public RubyString makeString(char string, Encoding encoding) {
return makeString(Character.toString(string), encoding);
}

public RubyString makeString(RubyClass stringClass, char string, Encoding encoding) {
return makeString(stringClass, Character.toString(string), encoding);
}

public RubyString makeString(ByteList bytes) {
return RubyString.fromByteList(coreLibrary.getStringClass(), bytes);
return makeString(coreLibrary.getStringClass(), bytes);
}

public RubyString makeString(RubyClass stringClass, ByteList bytes) {
return RubyString.fromByteList(stringClass, bytes);
}

public IRubyObject toJRuby(Object object) {
Expand Down
Expand Up @@ -126,7 +126,7 @@ public int count(RubyString[] otherStrings) {
public RubyString dump() {
ByteList outputBytes = StringSupport.dumpCommon(getContext().getRuntime(), bytes);

final RubyString result = getContext().makeString(outputBytes);
final RubyString result = getContext().makeString(getLogicalClass(), outputBytes);

return result;
}
Expand Down

0 comments on commit c25d417

Please sign in to comment.