Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1bb8f560d259
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 21f6cd60c91f
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 15, 2015

  1. Copy the full SHA
    6660f98 View commit details
  2. Copy the full SHA
    33afa45 View commit details
  3. Copy the full SHA
    21f6cd6 View commit details
75 changes: 71 additions & 4 deletions core/src/main/java/org/jruby/truffle/nodes/core/RegexpNodes.java
Original file line number Diff line number Diff line change
@@ -13,11 +13,16 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.joni.Option;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyEncoding;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyRegexp;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.util.ByteList;
@@ -175,9 +180,11 @@ public RubyString escape(RubyString pattern) {

}

@CoreMethod(names = "initialize", required = 1)
@CoreMethod(names = "initialize", required = 1, optional = 1, lowerFixnumParameters = 2)
public abstract static class InitializeNode extends CoreMethodNode {

private ConditionProfile booleanOptionsProfile = ConditionProfile.createBinaryProfile();

public InitializeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}
@@ -187,21 +194,53 @@ public InitializeNode(InitializeNode prev) {
}

@Specialization
public RubyRegexp initialize(RubyRegexp regexp, RubyString string) {
public RubyRegexp initialize(RubyRegexp regexp, RubyString string, @SuppressWarnings("unused") UndefinedPlaceholder options) {
notDesignedForCompilation();

regexp.initialize(this, string.getBytes());
return regexp;
}

@Specialization
public RubyRegexp initialize(RubyRegexp regexp, RubyRegexp from) {
public RubyRegexp initialize(RubyRegexp regexp, RubyString string, @SuppressWarnings("unused") RubyNilClass options) {
notDesignedForCompilation();

regexp.initialize(this, from.getSource()); // TODO: is copying needed?
return initialize(regexp, string, UndefinedPlaceholder.INSTANCE);
}

@Specialization
public RubyRegexp initialize(RubyRegexp regexp, RubyString string, boolean options) {
notDesignedForCompilation();

if (booleanOptionsProfile.profile(options)) {
return initialize(regexp, string, Option.IGNORECASE);
} else {
return initialize(regexp, string, UndefinedPlaceholder.INSTANCE);
}
}

@Specialization
public RubyRegexp initialize(RubyRegexp regexp, RubyString string, int options) {
notDesignedForCompilation();

regexp.initialize(this, string.getBytes(), options);
return regexp;
}

@Specialization(guards = "!isRubyNilClass(arguments[2])")
public RubyRegexp initialize(RubyRegexp regexp, RubyString string, Object options) {
notDesignedForCompilation();

return initialize(regexp, string, Option.IGNORECASE);
}

@Specialization
public RubyRegexp initialize(RubyRegexp regexp, RubyRegexp from, @SuppressWarnings("unused") UndefinedPlaceholder options) {
notDesignedForCompilation();

regexp.initialize(this, from.getSource()); // TODO: is copying needed?
return regexp;
}
}

@CoreMethod(names = "initialize_copy", visibility = Visibility.PRIVATE, required = 1)
@@ -266,6 +305,34 @@ public Object match(RubyRegexp regexp, RubyString string) {

}

@CoreMethod(names = "options")
public abstract static class OptionsNode extends CoreMethodNode {

private final ConditionProfile notYetInitializedProfile = ConditionProfile.createBinaryProfile();

public OptionsNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public OptionsNode(OptionsNode prev) {
super(prev);
}

@Specialization
public int options(RubyRegexp regexp) {
notDesignedForCompilation();

if (notYetInitializedProfile.profile(regexp.getRegex() == null)) {
CompilerDirectives.transferToInterpreter();

throw new RaiseException(getContext().getCoreLibrary().typeError("uninitialized Regexp", this));
}

return regexp.getRegex().getOptions();
}

}

@CoreMethod(names = "source")
public abstract static class SourceNode extends CoreMethodNode {

Original file line number Diff line number Diff line change
@@ -57,11 +57,15 @@ public RubyRegexp(RubyClass regexpClass, Regex regex, ByteList source) {
initialize(regex, source);
}

public void initialize(RubyNode currentNode, ByteList setSource) {
regex = compile(currentNode, getContext(), setSource, Option.DEFAULT);
public void initialize(RubyNode currentNode, ByteList setSource, int options) {
regex = compile(currentNode, getContext(), setSource, options);
source = setSource;
}

public void initialize(RubyNode currentNode, ByteList setSource) {
initialize(currentNode, setSource, Option.DEFAULT);
}

public void initialize(Regex setRegex, ByteList setSource) {
regex = setRegex;
source = setSource;
6 changes: 0 additions & 6 deletions spec/truffle/tags/core/regexp/new_tags.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
fails:Regexp.new works by default for subclasses with overridden #initialize
fails:Regexp.new given a String raises a RegexpError when passed an incorrect regexp
fails:Regexp.new given a String does not set Regexp options if only given one argument
fails:Regexp.new given a String does not set Regexp options if second argument is nil or false
fails:Regexp.new given a String sets options from second argument if it is one of the Fixnum option constants
fails:Regexp.new given a String accepts a Fixnum of two or more options ORed together as the second argument
fails:Regexp.new given a String treats any non-Fixnum, non-nil, non-false second argument as IGNORECASE
fails:Regexp.new given a String ignores the third argument if it is 'e' or 'euc' (case-insensitive)
fails:Regexp.new given a String ignores the third argument if it is 's' or 'sjis' (case-insensitive)
fails:Regexp.new given a String ignores the third argument if it is 'u' or 'utf8' (case-insensitive)
8 changes: 0 additions & 8 deletions spec/truffle/tags/core/regexp/options_tags.txt

This file was deleted.