|
28 | 28 |
|
29 | 29 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.__FUNC__;
|
30 | 30 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.__MODULE__;
|
| 31 | +import static com.oracle.graal.python.nodes.SpecialAttributeNames.__DOC__; |
31 | 32 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.__NAME__;
|
32 | 33 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.__SELF__;
|
33 | 34 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__CALL__;
|
@@ -183,4 +184,50 @@ Object getModule(PBuiltinMethod self, Object value) {
|
183 | 184 | return PNone.NONE;
|
184 | 185 | }
|
185 | 186 | }
|
| 187 | + |
| 188 | + @Builtin(name = __DOC__, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2, isGetter = true, isSetter = true) |
| 189 | + @GenerateNodeFactory |
| 190 | + abstract static class DocNode extends PythonBinaryBuiltinNode { |
| 191 | + @Child ReadAttributeFromObjectNode readFunc; |
| 192 | + |
| 193 | + private Object readFromFunc(Object func) { |
| 194 | + if (readFunc == null) { |
| 195 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 196 | + readFunc = insert(ReadAttributeFromObjectNode.create()); |
| 197 | + } |
| 198 | + return readFunc.execute(func, __DOC__); |
| 199 | + } |
| 200 | + |
| 201 | + @Specialization(guards = "isNoValue(none)") |
| 202 | + Object getModule(PMethod self, @SuppressWarnings("unused") PNone none, |
| 203 | + @Cached("create()") ReadAttributeFromObjectNode readSelf) { |
| 204 | + Object doc = readSelf.execute(self, __DOC__); |
| 205 | + if (doc == PNone.NO_VALUE) { |
| 206 | + return readFromFunc(self.getFunction()); |
| 207 | + } |
| 208 | + return doc; |
| 209 | + } |
| 210 | + |
| 211 | + @Specialization(guards = "isNoValue(none)") |
| 212 | + Object getModule(PBuiltinMethod self, @SuppressWarnings("unused") PNone none, |
| 213 | + @Cached("create()") ReadAttributeFromObjectNode readSelf) { |
| 214 | + Object doc = readSelf.execute(self, __DOC__); |
| 215 | + if (doc == PNone.NO_VALUE) { |
| 216 | + return readFromFunc(self.getFunction()); |
| 217 | + } |
| 218 | + return doc; |
| 219 | + } |
| 220 | + |
| 221 | + @Specialization(guards = {"!isNoValue(value)"}) |
| 222 | + Object getModule(PMethod self, Object value, |
| 223 | + @Cached("create()") WriteAttributeToObjectNode writeObject) { |
| 224 | + writeObject.execute(self, __DOC__, value); |
| 225 | + return PNone.NONE; |
| 226 | + } |
| 227 | + |
| 228 | + @Specialization(guards = {"!isNoValue(value)"}) |
| 229 | + Object getModule(@SuppressWarnings("unused") PBuiltinMethod self, @SuppressWarnings("unused") Object value) { |
| 230 | + throw raise(PythonBuiltinClassType.AttributeError, "attribute '__doc__' of 'builtin_function_or_method' objects is not writable"); |
| 231 | + } |
| 232 | + } |
186 | 233 | }
|
0 commit comments