|
40 | 40 | */
|
41 | 41 | package com.oracle.graal.python.builtins.objects;
|
42 | 42 |
|
43 |
| -import static com.oracle.graal.python.builtins.PythonBuiltinClassType.AttributeError; |
44 | 43 | import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REPR__;
|
45 | 44 | import static com.oracle.graal.python.nodes.StringLiterals.T_NONE;
|
46 | 45 |
|
|
52 | 51 | import com.oracle.graal.python.builtins.CoreFunctions;
|
53 | 52 | import com.oracle.graal.python.builtins.PythonBuiltinClassType;
|
54 | 53 | import com.oracle.graal.python.builtins.PythonBuiltins;
|
55 |
| -import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; |
56 |
| -import com.oracle.graal.python.builtins.objects.getsetdescriptor.GetSetDescriptor; |
57 |
| -import com.oracle.graal.python.builtins.objects.object.ObjectBuiltins; |
58 | 54 | import com.oracle.graal.python.builtins.objects.type.TpSlots;
|
59 |
| -import com.oracle.graal.python.builtins.objects.type.slots.TpSlotGetAttr.GetAttrBuiltinNode; |
60 | 55 | import com.oracle.graal.python.builtins.objects.type.slots.TpSlotInquiry.NbBoolBuiltinNode;
|
61 |
| -import com.oracle.graal.python.nodes.ErrorMessages; |
62 |
| -import com.oracle.graal.python.nodes.PRaiseNode; |
63 |
| -import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode; |
64 |
| -import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode; |
65 | 56 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
66 | 57 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
67 |
| -import com.oracle.graal.python.nodes.util.CannotCastException; |
68 |
| -import com.oracle.graal.python.nodes.util.CastToTruffleStringNode; |
69 |
| -import com.oracle.graal.python.runtime.object.PythonObjectFactory; |
70 |
| -import com.oracle.truffle.api.dsl.Bind; |
71 |
| -import com.oracle.truffle.api.dsl.Cached; |
72 | 58 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
73 | 59 | import com.oracle.truffle.api.dsl.GenerateUncached;
|
74 | 60 | import com.oracle.truffle.api.dsl.NodeFactory;
|
75 | 61 | import com.oracle.truffle.api.dsl.Specialization;
|
76 |
| -import com.oracle.truffle.api.frame.VirtualFrame; |
77 |
| -import com.oracle.truffle.api.nodes.Node; |
78 |
| -import com.oracle.truffle.api.strings.TruffleString; |
79 | 62 |
|
80 | 63 | @CoreFunctions(extendClasses = PythonBuiltinClassType.PNone)
|
81 | 64 | public final class NoneBuiltins extends PythonBuiltins {
|
@@ -106,55 +89,4 @@ static Object doNone(PNone none) {
|
106 | 89 | return T_NONE;
|
107 | 90 | }
|
108 | 91 | }
|
109 |
| - |
110 |
| - /** |
111 |
| - * XXX CPython's None doesn't declare its own __getattribute__, it inherits the object one. We |
112 |
| - * currently have to have one because of peculiarities in descriptor protocol. CPython has a |
113 |
| - * slot wrapper for __get__ that converts None to NULL, which is then treated as a descriptor |
114 |
| - * get on a type. object.__getattribute__ calls tp_descr_get which doesn't go through the |
115 |
| - * wrapper, so the None stays as None. IOW you can't express descriptor gets on None in terms of |
116 |
| - * __get__, i.e. None.__class__ is not the same as object.__dict__['__class__'].__get__(None, |
117 |
| - * type(None)). Since we don't distinguish between method and slot calls, this is the current |
118 |
| - * workaround that bypasses the descriptor __get__ handling and invokes the get function |
119 |
| - * directly. |
120 |
| - */ |
121 |
| - @Slot(value = SlotKind.tp_get_attro, isComplex = true) |
122 |
| - @GenerateNodeFactory |
123 |
| - public abstract static class GetAttributeNode extends GetAttrBuiltinNode { |
124 |
| - |
125 |
| - @Specialization |
126 |
| - static Object doIt(VirtualFrame frame, Object object, Object keyObj, |
127 |
| - @Bind("this") Node inliningTarget, |
128 |
| - @Cached LookupAttributeInMRONode.Dynamic lookup, |
129 |
| - @Cached CallUnaryMethodNode callGet, |
130 |
| - @Cached CastToTruffleStringNode castKeyToStringNode, |
131 |
| - @Cached PythonObjectFactory.Lazy factory, |
132 |
| - @Cached ObjectBuiltins.GetAttributeNode getAttributeNode, |
133 |
| - @Cached PRaiseNode.Lazy raiseNode) { |
134 |
| - assert object == PNone.NONE; |
135 |
| - TruffleString key; |
136 |
| - try { |
137 |
| - key = castKeyToStringNode.execute(inliningTarget, keyObj); |
138 |
| - } catch (CannotCastException e) { |
139 |
| - throw raiseNode.get(inliningTarget).raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTR_NAME_MUST_BE_STRING, keyObj); |
140 |
| - } |
141 |
| - |
142 |
| - Object descr = lookup.execute(PythonBuiltinClassType.PNone, key); |
143 |
| - if (descr == PNone.NO_VALUE) { |
144 |
| - throw raiseNode.get(inliningTarget).raise(AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, PNone.NONE, key); |
145 |
| - } |
146 |
| - if (descr instanceof GetSetDescriptor getSetDescriptor) { |
147 |
| - // Bypass getset_descriptor.__get__ |
148 |
| - assert getSetDescriptor.getGet() != null; |
149 |
| - return callGet.executeObject(frame, getSetDescriptor.getGet(), PNone.NONE); |
150 |
| - } |
151 |
| - if (descr instanceof PBuiltinFunction function) { |
152 |
| - // Bypass method_descriptor.__get__ |
153 |
| - assert !function.needsDeclaringType(); |
154 |
| - return factory.get(inliningTarget).createBuiltinMethod(PNone.NONE, function); |
155 |
| - } |
156 |
| - // Delegate classmethods, staticmethods etc. to object.__getattribute__ |
157 |
| - return getAttributeNode.execute(frame, PNone.NONE, key); |
158 |
| - } |
159 |
| - } |
160 | 92 | }
|
0 commit comments