|
38 | 38 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.__MRO__;
|
39 | 39 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.__NAME__;
|
40 | 40 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.__QUALNAME__;
|
| 41 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.MRO; |
41 | 42 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__ALLOC__;
|
42 | 43 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__CALL__;
|
43 | 44 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__DELETE__;
|
|
76 | 77 | import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
|
77 | 78 | import com.oracle.graal.python.builtins.objects.function.PFunction;
|
78 | 79 | import com.oracle.graal.python.builtins.objects.function.PKeyword;
|
| 80 | +import com.oracle.graal.python.builtins.objects.getsetdescriptor.HiddenPythonKey; |
79 | 81 | import com.oracle.graal.python.builtins.objects.list.PList;
|
80 | 82 | import com.oracle.graal.python.builtins.objects.mappingproxy.PMappingproxy;
|
81 | 83 | import com.oracle.graal.python.builtins.objects.object.PythonObject;
|
82 | 84 | import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
|
83 |
| -import com.oracle.graal.python.builtins.objects.str.PString; |
84 | 85 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
85 | 86 | import com.oracle.graal.python.builtins.objects.type.TypeBuiltinsFactory.CallNodeFactory;
|
| 87 | +import com.oracle.graal.python.builtins.objects.type.TypeNodes.CheckCompatibleForAssigmentNode; |
| 88 | +import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetBaseClassNode; |
| 89 | +import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetBestBaseClassNode; |
86 | 90 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroNode;
|
87 | 91 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode;
|
88 | 92 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetSubclassesNode;
|
|
112 | 116 | import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
|
113 | 117 | import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
|
114 | 118 | import com.oracle.graal.python.nodes.truffle.PythonTypes;
|
| 119 | +import com.oracle.graal.python.nodes.util.CannotCastException; |
| 120 | +import com.oracle.graal.python.nodes.util.CastToJavaStringNode; |
115 | 121 | import com.oracle.graal.python.nodes.util.SplitArgsNode;
|
116 | 122 | import com.oracle.graal.python.runtime.exception.PException;
|
117 | 123 | import com.oracle.graal.python.runtime.exception.PythonErrorType;
|
|
131 | 137 | import com.oracle.truffle.api.interop.InteropLibrary;
|
132 | 138 | import com.oracle.truffle.api.interop.UnsupportedMessageException;
|
133 | 139 | import com.oracle.truffle.api.library.CachedLibrary;
|
134 |
| -import com.oracle.graal.python.builtins.objects.getsetdescriptor.HiddenPythonKey; |
135 |
| -import com.oracle.graal.python.builtins.objects.type.TypeNodes.CheckCompatibleForAssigmentNode; |
136 |
| -import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetBaseClassNode; |
137 |
| -import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetBestBaseClassNode; |
138 |
| -import static com.oracle.graal.python.nodes.SpecialMethodNames.MRO; |
139 | 140 | import com.oracle.truffle.api.profiles.BranchProfile;
|
140 | 141 | import com.oracle.truffle.api.profiles.ConditionProfile;
|
141 | 142 |
|
@@ -837,28 +838,18 @@ Object setName(@SuppressWarnings("unused") PythonBuiltinClass cls, @SuppressWarn
|
837 | 838 | }
|
838 | 839 |
|
839 | 840 | @Specialization(guards = {"!isNoValue(value)", "!isPythonBuiltinClass(cls)"})
|
840 |
| - Object setName(PythonClass cls, String value) { |
841 |
| - if (containsNullCharacter(value)) { |
842 |
| - throw raise(PythonBuiltinClassType.ValueError, "type name must not contain null characters"); |
843 |
| - } |
844 |
| - cls.setName(value); |
845 |
| - return PNone.NONE; |
846 |
| - } |
847 |
| - |
848 |
| - @Specialization(guards = {"!isNoValue(value)", "!isPythonBuiltinClass(cls)", "isBuiltinString(value, profile)"}, limit = "1") |
849 |
| - Object setName(PythonClass cls, PString value, |
850 |
| - @Cached.Shared("builtinStringProfile") @Cached IsBuiltinClassProfile profile) { |
851 |
| - if (containsNullCharacter(value)) { |
852 |
| - throw raise(PythonBuiltinClassType.ValueError, "type name must not contain null characters"); |
853 |
| - } |
854 |
| - cls.setName(value.getValue()); |
855 |
| - return PNone.NONE; |
856 |
| - } |
857 |
| - |
858 |
| - @Specialization(guards = {"!isNoValue(value)", "!isPythonBuiltinClass(cls)", "!isBuiltinString(value, profile)"}, limit = "1") |
859 | 841 | Object setName(PythonClass cls, Object value,
|
860 |
| - @Cached.Shared("builtinStringProfile") @Cached IsBuiltinClassProfile profile) { |
861 |
| - throw raise(PythonBuiltinClassType.TypeError, "can only assign string to %p.__name__, not '%p'", cls, value); |
| 842 | + @Cached CastToJavaStringNode castToJavaStringNode) { |
| 843 | + try { |
| 844 | + String string = castToJavaStringNode.execute(value); |
| 845 | + if (containsNullCharacter(string)) { |
| 846 | + throw raise(PythonBuiltinClassType.ValueError, "type name must not contain null characters"); |
| 847 | + } |
| 848 | + cls.setName(string); |
| 849 | + return PNone.NONE; |
| 850 | + } catch (CannotCastException e) { |
| 851 | + throw raise(PythonBuiltinClassType.TypeError, "can only assign string to %p.__name__, not '%p'", cls, value); |
| 852 | + } |
862 | 853 | }
|
863 | 854 |
|
864 | 855 | @Specialization(guards = "isNoValue(value)")
|
@@ -962,22 +953,14 @@ Object setName(@SuppressWarnings("unused") PythonBuiltinClass cls, @SuppressWarn
|
962 | 953 | }
|
963 | 954 |
|
964 | 955 | @Specialization(guards = {"!isNoValue(value)", "!isPythonBuiltinClass(cls)"})
|
965 |
| - Object setName(PythonClass cls, String value) { |
966 |
| - cls.setQualName(value); |
967 |
| - return PNone.NONE; |
968 |
| - } |
969 |
| - |
970 |
| - @Specialization(guards = {"!isNoValue(value)", "!isPythonBuiltinClass(cls)", "isBuiltinString(value, profile)"}, limit = "1") |
971 |
| - Object setName(PythonClass cls, PString value, |
972 |
| - @Cached.Shared("builtinStringProfile") @Cached IsBuiltinClassProfile profile) { |
973 |
| - cls.setQualName(value.getValue()); |
974 |
| - return PNone.NONE; |
975 |
| - } |
976 |
| - |
977 |
| - @Specialization(guards = {"!isNoValue(value)", "!isPythonBuiltinClass(cls)", "!isBuiltinString(value, profile)"}, limit = "1") |
978 | 956 | Object setName(PythonClass cls, Object value,
|
979 |
| - @Cached.Shared("builtinStringProfile") @Cached IsBuiltinClassProfile profile) { |
980 |
| - throw raise(PythonBuiltinClassType.TypeError, "can only assign string to %p.__qualname__, not '%p'", cls, value); |
| 957 | + @Cached CastToJavaStringNode castToJavaStringNode) { |
| 958 | + try { |
| 959 | + cls.setQualName(castToJavaStringNode.execute(value)); |
| 960 | + return PNone.NONE; |
| 961 | + } catch (CannotCastException e) { |
| 962 | + throw raise(PythonBuiltinClassType.TypeError, "can only assign string to %p.__qualname__, not '%p'", cls, value); |
| 963 | + } |
981 | 964 | }
|
982 | 965 |
|
983 | 966 | @Specialization(guards = "isNoValue(value)")
|
|
0 commit comments