Skip to content

Commit 5f990d2

Browse files
committed
Externalize string literals used in PRaiseNode.raise.
1 parent 2c927a9 commit 5f990d2

File tree

147 files changed

+1714
-787
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+1714
-787
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ArrayModuleBuiltins.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -41,6 +41,7 @@
4141
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
4242
import com.oracle.graal.python.builtins.objects.range.PRange;
4343
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
44+
import com.oracle.graal.python.nodes.ErrorMessages;
4445
import com.oracle.graal.python.nodes.control.GetIteratorExpressionNode.GetIteratorNode;
4546
import com.oracle.graal.python.nodes.control.GetNextNode;
4647
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -181,7 +182,7 @@ PArray arrayIntInitializer(VirtualFrame frame, LazyPythonClass cls, @SuppressWar
181182
if (nextValue instanceof Integer) {
182183
intArray[i++] = (int) nextValue;
183184
} else {
184-
throw raise(ValueError, "integer argument expected, got %p", nextValue);
185+
throw raise(ValueError, ErrorMessages.ARG_EXPECTED_GOT, "Integer", nextValue);
185186
}
186187
}
187188

@@ -210,7 +211,7 @@ PArray arrayLongInitializer(VirtualFrame frame, LazyPythonClass cls, @SuppressWa
210211
if (nextValue instanceof Number) {
211212
longArray[i++] = longValue((Number) nextValue);
212213
} else {
213-
throw raise(ValueError, "integer argument expected, got %p", nextValue);
214+
throw raise(ValueError, ErrorMessages.ARG_EXPECTED_GOT, "Integer", nextValue);
214215
}
215216
}
216217

@@ -241,7 +242,7 @@ PArray arrayDoubleInitializer(VirtualFrame frame, LazyPythonClass cls, @Suppress
241242
} else if (nextValue instanceof Double) {
242243
doubleArray[i++] = (double) nextValue;
243244
} else {
244-
throw raise(ValueError, "double value expected");
245+
throw raise(ValueError, ErrorMessages.VALUE_EXPECTED, "double");
245246
}
246247
}
247248

@@ -253,14 +254,14 @@ PArray arrayDoubleInitializer(VirtualFrame frame, LazyPythonClass cls, @Suppress
253254
PArray arrayWithObjectInitializer(@SuppressWarnings("unused") LazyPythonClass cls, @SuppressWarnings("unused") String typeCode, Object initializer) {
254255
if (!(isIntArray(typeCode) || isByteArray(typeCode) || isDoubleArray(typeCode) || isCharArray(typeCode))) {
255256
// TODO implement support for typecodes: b, B, u, h, H, i, I, l, L, q, Q, f or d
256-
throw raise(ValueError, "bad typecode (must be i, d, b, B, or l)");
257+
throw raise(ValueError, ErrorMessages.BAD_TYPECODE);
257258
}
258259
throw new RuntimeException("Unsupported initializer " + initializer);
259260
}
260261

261262
@Specialization(guards = "!isString(typeCode)")
262263
PArray noArray(@SuppressWarnings("unused") LazyPythonClass cls, Object typeCode, @SuppressWarnings("unused") Object initializer) {
263-
throw raise(TypeError, "array() argument 1 must be a unicode character, not %p", typeCode);
264+
throw raise(TypeError, ErrorMessages.ARG_MUST_BE_UNICODE, "array()", 1, typeCode);
264265
}
265266

266267
@TruffleBoundary
@@ -286,14 +287,14 @@ private PArray makeEmptyArray(LazyPythonClass cls, char type) {
286287

287288
protected CastToByteNode createCast() {
288289
return CastToByteNode.create(val -> {
289-
throw raise(OverflowError, "signed char is greater than maximum");
290+
throw raise(OverflowError, ErrorMessages.SIGNED_CHAR_GREATER_THAN_MAX);
290291
}, null);
291292

292293
}
293294

294295
@TruffleBoundary
295296
private void typeError(String typeCode, Object initializer) {
296-
throw raise(TypeError, "cannot use a %p to initialize an array with typecode '%s'", initializer, typeCode);
297+
throw raise(TypeError, ErrorMessages.CANNOT_USE_TO_INITIALIZE_ARRAY, initializer, typeCode);
297298
}
298299
}
299300
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BinasciiModuleBuiltins.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
6565
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
6666
import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
67+
import com.oracle.graal.python.nodes.ErrorMessages;
6768
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
6869
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
6970
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -173,7 +174,7 @@ PBytes a2b(PythonModule self, Object buffer,
173174
try {
174175
return a2b(self, bufferLib.getBufferBytes(buffer));
175176
} catch (UnsupportedMessageException e) {
176-
throw raise(SystemError, "bad argument to internal function");
177+
throw raise(SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
177178
}
178179
}
179180

@@ -203,11 +204,11 @@ private int digitValue(PythonModule self, char b) {
203204
}
204205

205206
private PException oddLengthError(PythonModule self) {
206-
return raise((LazyPythonClass) getAttrNode().execute(self, ERROR), "Odd-length string");
207+
return raise((LazyPythonClass) getAttrNode().execute(self, ERROR), ErrorMessages.ODD_LENGTH_STRING);
207208
}
208209

209210
private PException nonHexError(PythonModule self) {
210-
return raise((LazyPythonClass) getAttrNode().execute(self, ERROR), "Non-hexadecimal digit found");
211+
return raise((LazyPythonClass) getAttrNode().execute(self, ERROR), ErrorMessages.NON_HEX_DIGIT_FOUND);
211212
}
212213

213214
private ReadAttributeFromObjectNode getAttrNode() {
@@ -310,7 +311,7 @@ PBytes b2aMemory(VirtualFrame frame, PMemoryView data, long newline,
310311
if (isBytesProfile.profile(bytesObj instanceof PBytes)) {
311312
return b2aBytesLike((PBytes) bytesObj, newline);
312313
}
313-
throw raise(SystemError, "could not get bytes of memoryview");
314+
throw raise(SystemError, ErrorMessages.COULD_NOT_GET_BYTES_OF_MEMORYVIEW);
314315
}
315316

316317
@Specialization
@@ -328,14 +329,14 @@ PBytes b2aMmeory(VirtualFrame frame, PMemoryView data, Object newline,
328329

329330
@Fallback
330331
PBytes b2sGeneral(Object data, @SuppressWarnings("unused") Object newline) {
331-
throw raise(PythonBuiltinClassType.TypeError, "a bytes-like object is required, not '%p'", data);
332+
throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, data);
332333
}
333334

334335
private Object asPInt(Object obj, PythonObjectLibrary lib) {
335336
if (lib.canBePInt(obj)) {
336337
return lib.asPInt(obj);
337338
}
338-
throw raise(PythonBuiltinClassType.TypeError, "an integer is required (got type %p)", obj);
339+
throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.INTEGER_REQUIRED_GOT, obj);
339340
}
340341
}
341342

@@ -352,7 +353,7 @@ PBytes b2a(Object buffer,
352353
try {
353354
return b2a(bufferLib.getBufferBytes(buffer));
354355
} catch (UnsupportedMessageException e) {
355-
throw raise(SystemError, "bad argument to internal function");
356+
throw raise(SystemError, ErrorMessages.BAD_ARG_TO_INTERNAL_FUNC);
356357
}
357358
}
358359

0 commit comments

Comments
 (0)