|
43 | 43 | import java.util.ArrayList;
|
44 | 44 | import java.util.Arrays;
|
45 | 45 | import java.util.HashSet;
|
| 46 | +import java.util.List; |
46 | 47 | import java.util.Set;
|
47 | 48 |
|
48 | 49 | import com.oracle.graal.python.PythonLanguage;
|
| 50 | +import com.oracle.graal.python.builtins.PythonBuiltinClassType; |
49 | 51 | import com.oracle.graal.python.builtins.objects.function.Signature;
|
50 | 52 | import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
|
51 | 53 | import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
|
|
57 | 59 | import com.oracle.graal.python.nodes.argument.ReadVarKeywordsNode;
|
58 | 60 | import com.oracle.graal.python.nodes.frame.FrameSlotIDs;
|
59 | 61 | import com.oracle.graal.python.nodes.frame.GlobalNode;
|
| 62 | +import com.oracle.graal.python.nodes.function.FunctionDefinitionNode; |
60 | 63 | import com.oracle.graal.python.nodes.generator.GeneratorFunctionRootNode;
|
61 | 64 | import com.oracle.graal.python.nodes.literal.SimpleLiteralNode;
|
62 | 65 | import com.oracle.truffle.api.CompilerDirectives;
|
63 | 66 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
64 | 67 | import com.oracle.truffle.api.RootCallTarget;
|
65 | 68 | import com.oracle.truffle.api.interop.UnsupportedMessageException;
|
66 | 69 | import com.oracle.truffle.api.library.ExportMessage;
|
| 70 | +import com.oracle.truffle.api.nodes.Node; |
67 | 71 | import com.oracle.truffle.api.nodes.NodeUtil;
|
| 72 | +import com.oracle.truffle.api.nodes.NodeVisitor; |
68 | 73 | import com.oracle.truffle.api.nodes.RootNode;
|
69 | 74 | import com.oracle.truffle.api.source.SourceSection;
|
70 | 75 |
|
@@ -235,7 +240,21 @@ private static Object[] extractVarnames(RootNode rootNode, String[] parameterIds
|
235 | 240 |
|
236 | 241 | @TruffleBoundary
|
237 | 242 | private static Object[] extractConstants(RootNode rootNode) {
|
238 |
| - return NodeUtil.findAllNodeInstances(rootNodeForExtraction(rootNode), SimpleLiteralNode.class).stream().map((n) -> n.getValue()).toArray(); |
| 243 | + List<Object> constants = new ArrayList<>(); |
| 244 | + rootNode.accept(new NodeVisitor() { |
| 245 | + public boolean visit(Node node) { |
| 246 | + if (node instanceof SimpleLiteralNode) { |
| 247 | + constants.add(((SimpleLiteralNode) node).getValue()); |
| 248 | + return false; |
| 249 | + } else if (node instanceof FunctionDefinitionNode) { |
| 250 | + constants.add(new PCode(PythonBuiltinClassType.PCode, ((FunctionDefinitionNode) node).getCallTarget())); |
| 251 | + return false; |
| 252 | + } else { |
| 253 | + return true; |
| 254 | + } |
| 255 | + } |
| 256 | + }); |
| 257 | + return constants.toArray(); |
239 | 258 | }
|
240 | 259 |
|
241 | 260 | @TruffleBoundary
|
|
0 commit comments