Skip to content

Commit 42e9625

Browse files
committed
Rename CheckIfPatternsMatchedNode to NoMatchingPatternError and simplify
1 parent cb62fc2 commit 42e9625

File tree

4 files changed

+40
-51
lines changed

4 files changed

+40
-51
lines changed

src/main/java/org/truffleruby/core/exception/CoreExceptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,9 @@ public RubyException noMemoryError(Node currentNode, OutOfMemoryError javaThrowa
381381
// NoMatchingPatternError
382382

383383
@TruffleBoundary
384-
public RubyException noMatchingPatternError(String message, Node currentNode) {
384+
public RubyException noMatchingPatternError(Object errorMessage, Node currentNode) {
385+
assert RubyStringLibrary.getUncached().isRubyString(errorMessage);
385386
RubyClass exceptionClass = context.getCoreLibrary().noMatchingPatternErrorClass;
386-
RubyString errorMessage = StringOperations.createUTF8String(context, language, message);
387387
return ExceptionOperations.createRubyException(context, exceptionClass, errorMessage, currentNode, null);
388388
}
389389

src/main/java/org/truffleruby/language/control/CheckIfPatternsMatchedNode.java

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2022, 2023 Oracle and/or its affiliates. All rights reserved. This
3+
* code is released under a tri EPL/GPL/LGPL license. You can use it,
4+
* redistribute it and/or modify it under the terms of the:
5+
*
6+
* Eclipse Public License version 2.0, or
7+
* GNU General Public License version 2, or
8+
* GNU Lesser General Public License version 2.1.
9+
*/
10+
package org.truffleruby.language.control;
11+
12+
import com.oracle.truffle.api.dsl.Cached;
13+
import com.oracle.truffle.api.dsl.NodeChild;
14+
import com.oracle.truffle.api.dsl.Specialization;
15+
import org.truffleruby.language.RubyContextSourceNode;
16+
17+
import org.truffleruby.language.RubyNode;
18+
import org.truffleruby.language.dispatch.DispatchNode;
19+
20+
@NodeChild(value = "expressionNode", type = RubyNode.class)
21+
public abstract class NoMatchingPatternNode extends RubyContextSourceNode {
22+
23+
protected abstract RubyNode getExpressionNode();
24+
25+
@Specialization
26+
protected Object noMatchingPattern(Object expression,
27+
@Cached DispatchNode inspectNode) {
28+
Object inspected = inspectNode.call(coreLibrary().truffleTypeModule, "rb_inspect", expression);
29+
throw new RaiseException(getContext(), coreExceptions().noMatchingPatternError(inspected, this));
30+
}
31+
32+
@Override
33+
public RubyNode cloneUninitialized() {
34+
return NoMatchingPatternNodeGen.create(getExpressionNode().cloneUninitialized()).copyFlags(this);
35+
}
36+
}

src/main/java/org/truffleruby/parser/BodyTranslator.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
import org.truffleruby.language.control.AndNode;
7373
import org.truffleruby.language.control.BreakID;
7474
import org.truffleruby.language.control.BreakNode;
75-
import org.truffleruby.language.control.CheckIfPatternsMatchedNode;
7675
import org.truffleruby.language.control.DeferredRaiseException;
7776
import org.truffleruby.language.control.DynamicReturnNode;
7877
import org.truffleruby.language.control.FrameOnStackNode;
@@ -81,6 +80,7 @@
8180
import org.truffleruby.language.control.InvalidReturnNode;
8281
import org.truffleruby.language.control.LocalReturnNode;
8382
import org.truffleruby.language.control.NextNode;
83+
import org.truffleruby.language.control.NoMatchingPatternNodeGen;
8484
import org.truffleruby.language.control.NotNode;
8585
import org.truffleruby.language.control.OnceNode;
8686
import org.truffleruby.language.control.OrLazyValueDefinedNode;
@@ -853,16 +853,7 @@ public RubyNode visitCaseInNode(CaseInParseNode node) {
853853

854854
RubyNode elseNode;
855855
if (node.getElseNode() == null) {
856-
RubyCallNodeParameters inspectCallParameters = new RubyCallNodeParameters(
857-
NodeUtil.cloneNode(readTemp),
858-
"inspect",
859-
null,
860-
EmptyArgumentsDescriptor.INSTANCE,
861-
RubyNode.EMPTY_ARRAY,
862-
false,
863-
true);
864-
RubyNode inspected = language.coreMethodAssumptions.createCallNode(inspectCallParameters);
865-
elseNode = new CheckIfPatternsMatchedNode(inspected);
856+
elseNode = NoMatchingPatternNodeGen.create(readTemp);
866857
} else {
867858
elseNode = translateNodeOrNil(sourceSection, node.getElseNode());
868859
}

0 commit comments

Comments
 (0)