|
41 | 41 | import com.oracle.graal.python.builtins.objects.common.HashingStorage;
|
42 | 42 | import com.oracle.graal.python.builtins.objects.function.PArguments;
|
43 | 43 | import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
|
| 44 | +import com.oracle.graal.python.builtins.objects.function.PFunction; |
44 | 45 | import com.oracle.graal.python.builtins.objects.function.PKeyword;
|
| 46 | +import com.oracle.graal.python.builtins.objects.function.PythonCallable; |
45 | 47 | import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
|
| 48 | +import com.oracle.graal.python.builtins.objects.method.PMethod; |
46 | 49 | import com.oracle.graal.python.builtins.objects.module.PythonModule;
|
47 | 50 | import com.oracle.graal.python.builtins.objects.object.PythonObject;
|
| 51 | +import com.oracle.graal.python.builtins.objects.type.PythonClass; |
48 | 52 | import com.oracle.graal.python.nodes.BuiltinNames;
|
49 | 53 | import com.oracle.graal.python.nodes.NodeFactory;
|
50 | 54 | import com.oracle.graal.python.nodes.PNode;
|
|
86 | 90 | import com.oracle.truffle.api.object.Shape;
|
87 | 91 | import com.oracle.truffle.api.source.Source;
|
88 | 92 | import com.oracle.truffle.api.source.Source.SourceBuilder;
|
| 93 | +import com.oracle.truffle.api.source.SourceSection; |
89 | 94 |
|
90 |
| -@TruffleLanguage.Registration(id = PythonLanguage.ID, name = PythonLanguage.NAME, version = PythonLanguage.VERSION, mimeType = PythonLanguage.MIME_TYPE, interactive = true, internal = false, contextPolicy = TruffleLanguage.ContextPolicy.SHARED) |
| 95 | +@TruffleLanguage.Registration(id = PythonLanguage.ID, name = PythonLanguage.NAME, version = PythonLanguage.VERSION, characterMimeTypes = PythonLanguage.MIME_TYPE, interactive = true, internal = false, contextPolicy = TruffleLanguage.ContextPolicy.SHARED) |
91 | 96 | @ProvidedTags({StandardTags.CallTag.class, StandardTags.StatementTag.class, StandardTags.RootTag.class, StandardTags.TryBlockTag.class, StandardTags.ExpressionTag.class,
|
92 | 97 | DebuggerTags.AlwaysHalt.class})
|
93 | 98 | public final class PythonLanguage extends TruffleLanguage<PythonContext> {
|
@@ -380,6 +385,25 @@ protected Iterable<Scope> findTopScopes(PythonContext context) {
|
380 | 385 | return scopes;
|
381 | 386 | }
|
382 | 387 |
|
| 388 | + @Override |
| 389 | + @TruffleBoundary |
| 390 | + protected SourceSection findSourceLocation(PythonContext context, Object value) { |
| 391 | + if (value instanceof PFunction || value instanceof PMethod) { |
| 392 | + PythonCallable callable = (PythonCallable) value; |
| 393 | + return callable.getCallTarget().getRootNode().getSourceSection(); |
| 394 | + } else if (value instanceof PCode) { |
| 395 | + return ((PCode) value).getRootNode().getSourceSection(); |
| 396 | + } else if (value instanceof PythonClass) { |
| 397 | + for (String k : ((PythonClass) value).getAttributeNames()) { |
| 398 | + SourceSection attrSourceLocation = findSourceLocation(context, ((PythonClass) value).getAttribute(k)); |
| 399 | + if (attrSourceLocation != null) { |
| 400 | + return attrSourceLocation; |
| 401 | + } |
| 402 | + } |
| 403 | + } |
| 404 | + return null; |
| 405 | + } |
| 406 | + |
383 | 407 | @Override
|
384 | 408 | protected String toString(PythonContext context, Object value) {
|
385 | 409 | final PythonModule builtins = context.getBuiltins();
|
|
0 commit comments