Skip to content

Commit ee8400a

Browse files
committed
Push SequenceStorage.toString down
1 parent 1674bb1 commit ee8400a

File tree

6 files changed

+28
-36
lines changed

6 files changed

+28
-36
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/BasicSequenceStorage.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626
package com.oracle.graal.python.runtime.sequence.storage;
2727

28+
import com.oracle.truffle.api.CompilerAsserts;
2829
import com.oracle.truffle.api.CompilerDirectives;
2930

3031
public abstract class BasicSequenceStorage extends SequenceStorage {
@@ -69,4 +70,18 @@ public void minimizeCapacity() {
6970
capacity = length;
7071
}
7172

73+
@Override
74+
public String toString() {
75+
CompilerAsserts.neverPartOfCompilation();
76+
StringBuilder str = new StringBuilder(getClass().getSimpleName()).append('[');
77+
int len = length > 10 ? 10 : length;
78+
for (int i = 0; i < len; i++) {
79+
str.append(i == 0 ? "" : ", ");
80+
str.append(getItemNormalized(i));
81+
}
82+
if (length > 10) {
83+
str.append("...").append('(').append(length).append(')');
84+
}
85+
return str.append(']').toString();
86+
}
7287
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/EmptySequenceStorage.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.oracle.graal.python.nodes.ErrorMessages;
3434
import com.oracle.graal.python.nodes.PRaiseNode;
3535
import com.oracle.graal.python.util.PythonUtils;
36+
import com.oracle.truffle.api.CompilerAsserts;
3637
import com.oracle.truffle.api.CompilerDirectives;
3738
import com.oracle.truffle.api.library.ExportLibrary;
3839
import com.oracle.truffle.api.library.ExportMessage;
@@ -143,6 +144,12 @@ public ListStorageType getElementType() {
143144
return ListStorageType.Empty;
144145
}
145146

147+
@Override
148+
public String toString() {
149+
CompilerAsserts.neverPartOfCompilation();
150+
return "EmptySequenceStorage[]";
151+
}
152+
146153
@ExportMessage
147154
@SuppressWarnings("static-method")
148155
boolean isBuffer() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/NativeByteSequenceStorage.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
4444
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions;
4545
import com.oracle.graal.python.builtins.objects.cext.structs.CStructAccess;
46-
import com.oracle.truffle.api.CompilerAsserts;
4746
import com.oracle.truffle.api.dsl.Cached;
4847
import com.oracle.truffle.api.library.ExportLibrary;
4948
import com.oracle.truffle.api.library.ExportMessage;
@@ -72,12 +71,6 @@ public ListStorageType getElementType() {
7271
return ListStorageType.Byte;
7372
}
7473

75-
@Override
76-
public String toString(boolean isList) {
77-
CompilerAsserts.neverPartOfCompilation();
78-
return String.format("%s(len=%d, cap=%d) at %s%s", isList ? "[" : "(", length, capacity, getPtr(), isList ? "]" : ")");
79-
}
80-
8174
@ExportMessage
8275
@SuppressWarnings("static-method")
8376
boolean isBuffer() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/NativeObjectSequenceStorage.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
package com.oracle.graal.python.runtime.sequence.storage;
4242

4343
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions;
44-
import com.oracle.truffle.api.CompilerAsserts;
4544

4645
public final class NativeObjectSequenceStorage extends NativeSequenceStorage {
4746

@@ -65,10 +64,4 @@ public static NativeObjectSequenceStorage create(Object ptr, int length, int cap
6564
public ListStorageType getElementType() {
6665
return ListStorageType.Generic;
6766
}
68-
69-
@Override
70-
public String toString(boolean isList) {
71-
CompilerAsserts.neverPartOfCompilation();
72-
return String.format("%s(len=%d, cap=%d) at %s%s", isList ? "[" : "(", length, capacity, getPtr(), isList ? "]" : ")");
73-
}
7467
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/NativeSequenceStorage.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.logging.Level;
4444

4545
import com.oracle.graal.python.PythonLanguage;
46+
import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext;
4647
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeStorageReference;
4748
import com.oracle.graal.python.util.PythonUtils;
4849
import com.oracle.truffle.api.CompilerDirectives;
@@ -171,4 +172,9 @@ public final void copyItem(int idxTo, int idxFrom) {
171172
public final Object getInternalArrayObject() {
172173
return ptr;
173174
}
175+
176+
@Override
177+
public String toString() {
178+
return getClass().getSimpleName() + "(ptr=" + CApiContext.asHex(ptr) + ", length=" + length + ", capacity=" + capacity + ", ownsMemory=" + hasReference() + ")";
179+
}
174180
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/SequenceStorage.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
*/
2626
package com.oracle.graal.python.runtime.sequence.storage;
2727

28-
import com.oracle.truffle.api.CompilerAsserts;
29-
3028
public abstract class SequenceStorage {
3129

3230
public enum ListStorageType {
@@ -112,24 +110,4 @@ public final int getCapacity() {
112110
public abstract void ensureCapacity(int newCapacity);
113111

114112
public abstract void copyItem(int idxTo, int idxFrom);
115-
116-
@Override
117-
public String toString() {
118-
CompilerAsserts.neverPartOfCompilation();
119-
return getClass().getSimpleName() + toString(true);
120-
}
121-
122-
public String toString(boolean isList) {
123-
CompilerAsserts.neverPartOfCompilation();
124-
StringBuilder str = new StringBuilder(isList ? "[" : "(");
125-
int len = length > 10 ? 10 : length;
126-
for (int i = 0; i < len; i++) {
127-
str.append(i == 0 ? "" : ", ");
128-
str.append(getItemNormalized(i));
129-
}
130-
if (length > 10) {
131-
str.append("...").append('(').append(length).append(')');
132-
}
133-
return str.append(isList ? ']' : ')').toString();
134-
}
135113
}

0 commit comments

Comments
 (0)