|
44 | 44 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
|
45 | 45 |
|
46 | 46 | import java.io.UnsupportedEncodingException;
|
47 |
| -import java.nio.charset.StandardCharsets; |
48 | 47 | import java.util.List;
|
49 | 48 |
|
50 | 49 | import com.oracle.graal.python.PythonLanguage;
|
51 | 50 | import com.oracle.graal.python.builtins.Builtin;
|
52 | 51 | import com.oracle.graal.python.builtins.CoreFunctions;
|
53 | 52 | import com.oracle.graal.python.builtins.PythonBuiltins;
|
54 |
| -import com.oracle.graal.python.builtins.objects.bytes.BytesUtils; |
55 |
| -import com.oracle.graal.python.builtins.objects.bytes.PBytesLike; |
56 |
| -import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes; |
57 |
| -import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.ToByteArrayNodeGen; |
58 | 53 | import com.oracle.graal.python.builtins.objects.function.PFunction;
|
59 | 54 | import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
|
60 |
| -import com.oracle.graal.python.builtins.objects.str.PString; |
61 |
| -import com.oracle.graal.python.nodes.ErrorMessages; |
62 | 55 | import com.oracle.graal.python.nodes.call.CallNode;
|
63 | 56 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
64 | 57 | import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
|
65 |
| -import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode; |
66 | 58 | import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
|
67 | 59 | import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
|
68 | 60 | import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
|
69 | 61 | import com.oracle.graal.python.runtime.PythonContext;
|
70 | 62 | import com.oracle.graal.python.runtime.PythonCore;
|
71 | 63 | import com.oracle.graal.python.runtime.PythonOptions;
|
72 |
| -import com.oracle.graal.python.runtime.exception.PythonErrorType; |
73 |
| -import com.oracle.truffle.api.CompilerAsserts; |
74 | 64 | import com.oracle.truffle.api.CompilerDirectives;
|
75 | 65 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
76 | 66 | import com.oracle.truffle.api.dsl.Cached;
|
77 | 67 | import com.oracle.truffle.api.dsl.CachedContext;
|
78 |
| -import com.oracle.truffle.api.dsl.Fallback; |
79 | 68 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
80 | 69 | import com.oracle.truffle.api.dsl.NodeFactory;
|
81 | 70 | import com.oracle.truffle.api.dsl.Specialization;
|
@@ -105,79 +94,6 @@ public void initialize(PythonCore core) {
|
105 | 94 | super.initialize(core);
|
106 | 95 | }
|
107 | 96 |
|
108 |
| - /** |
109 |
| - * Replaces any <it>quoted</it> escape sequence like {@code "\\n"} (two characters; backslash + |
110 |
| - * 'n') by its single character like {@code "\n"} (one character; newline). |
111 |
| - */ |
112 |
| - @Builtin(name = "_process_escape_sequences", minNumOfPositionalArgs = 1) |
113 |
| - @GenerateNodeFactory |
114 |
| - abstract static class ProcessEscapeSequences extends PythonUnaryBuiltinNode { |
115 |
| - |
116 |
| - @Child private SequenceStorageNodes.ToByteArrayNode toByteArrayNode; |
117 |
| - |
118 |
| - @Specialization |
119 |
| - Object run(PString str) { |
120 |
| - return run(str.getValue()); |
121 |
| - } |
122 |
| - |
123 |
| - @Specialization |
124 |
| - @TruffleBoundary(transferToInterpreterOnException = false, allowInlining = true) |
125 |
| - Object run(String str) { |
126 |
| - if (containsBackslash(str)) { |
127 |
| - StringBuilder sb = BytesUtils.decodeEscapes(getCore(), str, true); |
128 |
| - return sb.toString(); |
129 |
| - } |
130 |
| - return str; |
131 |
| - } |
132 |
| - |
133 |
| - @Specialization |
134 |
| - Object run(PBytesLike str) { |
135 |
| - byte[] bytes = doBytes(getToByteArrayNode().execute(str.getSequenceStorage())); |
136 |
| - return factory().createByteArray(bytes); |
137 |
| - } |
138 |
| - |
139 |
| - @Specialization(guards = "bufferLib.isBuffer(buffer)", limit = "3") |
140 |
| - Object run(Object buffer, |
141 |
| - @CachedLibrary("buffer") PythonObjectLibrary bufferLib) { |
142 |
| - byte[] bytes; |
143 |
| - try { |
144 |
| - bytes = bufferLib.getBufferBytes(buffer); |
145 |
| - } catch (UnsupportedMessageException e) { |
146 |
| - throw CompilerDirectives.shouldNotReachHere(); |
147 |
| - } |
148 |
| - return factory().createByteArray(bytes); |
149 |
| - } |
150 |
| - |
151 |
| - @TruffleBoundary(transferToInterpreterOnException = false, allowInlining = true) |
152 |
| - private byte[] doBytes(byte[] str) { |
153 |
| - StringBuilder sb = BytesUtils.decodeEscapes(getCore(), new String(str, StandardCharsets.US_ASCII), true); |
154 |
| - return sb.toString().getBytes(StandardCharsets.US_ASCII); |
155 |
| - } |
156 |
| - |
157 |
| - private static boolean containsBackslash(String str) { |
158 |
| - CompilerAsserts.neverPartOfCompilation(); |
159 |
| - for (int i = 0; i < str.length(); i++) { |
160 |
| - if (str.charAt(i) == '\\') { |
161 |
| - return true; |
162 |
| - } |
163 |
| - } |
164 |
| - return false; |
165 |
| - } |
166 |
| - |
167 |
| - @Fallback |
168 |
| - Object run(Object o) { |
169 |
| - throw raise(PythonErrorType.TypeError, ErrorMessages.EXPECTED_S_NOT_P, "string", o); |
170 |
| - } |
171 |
| - |
172 |
| - private SequenceStorageNodes.ToByteArrayNode getToByteArrayNode() { |
173 |
| - if (toByteArrayNode == null) { |
174 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
175 |
| - toByteArrayNode = insert(ToByteArrayNodeGen.create()); |
176 |
| - } |
177 |
| - return toByteArrayNode; |
178 |
| - } |
179 |
| - } |
180 |
| - |
181 | 97 | abstract static class ToRegexSourceNode extends Node {
|
182 | 98 |
|
183 | 99 | public abstract Source execute(Object pattern, String flags);
|
|
0 commit comments