|
38 | 38 | import java.util.concurrent.Semaphore;
|
39 | 39 | import java.util.logging.Level;
|
40 | 40 |
|
41 |
| -import com.oracle.graal.python.pegparser.tokenizer.SourceRange; |
42 | 41 | import org.graalvm.options.OptionDescriptors;
|
43 | 42 | import org.graalvm.options.OptionKey;
|
44 | 43 | import org.graalvm.options.OptionValues;
|
|
64 | 63 | import com.oracle.graal.python.compiler.CompilationUnit;
|
65 | 64 | import com.oracle.graal.python.compiler.Compiler;
|
66 | 65 | import com.oracle.graal.python.nodes.HiddenAttributes;
|
67 |
| -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; |
68 | 66 | import com.oracle.graal.python.nodes.PRootNode;
|
69 | 67 | import com.oracle.graal.python.nodes.RootNodeFactory;
|
| 68 | +import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; |
70 | 69 | import com.oracle.graal.python.nodes.control.TopLevelExceptionHandler;
|
71 | 70 | import com.oracle.graal.python.nodes.expression.ExpressionNode;
|
72 | 71 | import com.oracle.graal.python.nodes.util.BadOPCodeNode;
|
73 | 72 | import com.oracle.graal.python.parser.PythonParserImpl;
|
| 73 | +import com.oracle.graal.python.pegparser.ErrorCallback; |
74 | 74 | import com.oracle.graal.python.pegparser.FExprParser;
|
75 | 75 | import com.oracle.graal.python.pegparser.InputType;
|
76 | 76 | import com.oracle.graal.python.pegparser.NodeFactoryImp;
|
77 | 77 | import com.oracle.graal.python.pegparser.Parser;
|
78 |
| -import com.oracle.graal.python.pegparser.ErrorCallback; |
79 | 78 | import com.oracle.graal.python.pegparser.ParserTokenizer;
|
80 | 79 | import com.oracle.graal.python.pegparser.sst.ExprTy;
|
81 | 80 | import com.oracle.graal.python.pegparser.sst.ModTy;
|
| 81 | +import com.oracle.graal.python.pegparser.tokenizer.SourceRange; |
82 | 82 | import com.oracle.graal.python.runtime.GilNode;
|
83 | 83 | import com.oracle.graal.python.runtime.PythonContext;
|
84 | 84 | import com.oracle.graal.python.runtime.PythonContext.PythonThreadState;
|
@@ -166,6 +166,8 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
|
166 | 166 | public static final int RELEASE_LEVEL_FINAL = 0xF;
|
167 | 167 | public static final int RELEASE_LEVEL = RELEASE_LEVEL_ALPHA;
|
168 | 168 | public static final TruffleString RELEASE_LEVEL_STRING;
|
| 169 | + public static final TruffleString DEFAULT_FILENAME = tsLiteral("<string>"); |
| 170 | + |
169 | 171 | static {
|
170 | 172 | switch (RELEASE_LEVEL) {
|
171 | 173 | case RELEASE_LEVEL_ALPHA:
|
@@ -581,13 +583,22 @@ public SourceSection getSourceSection() {
|
581 | 583 | instance = PythonObjectFactory.getUncached().createBaseException(cls, message, PythonUtils.EMPTY_OBJECT_ARRAY);
|
582 | 584 | final Object[] excAttrs = SyntaxErrorBuiltins.SYNTAX_ERROR_ATTR_FACTORY.create();
|
583 | 585 | SourceSection section = location.getSourceSection();
|
584 |
| - TruffleString path = toTruffleStringUncached(source.getPath()); |
585 |
| - excAttrs[SyntaxErrorBuiltins.IDX_FILENAME] = (path != null) ? path : source.getName() != null ? toTruffleStringUncached(source.getName()) : tsLiteral("<string>"); |
| 586 | + TruffleString filename = toTruffleStringUncached(source.getPath()); |
| 587 | + if (filename == null) { |
| 588 | + filename = toTruffleStringUncached(source.getName()); |
| 589 | + if (filename == null) { |
| 590 | + filename = DEFAULT_FILENAME; |
| 591 | + } |
| 592 | + } |
| 593 | + excAttrs[SyntaxErrorBuiltins.IDX_FILENAME] = filename; |
586 | 594 | excAttrs[SyntaxErrorBuiltins.IDX_LINENO] = section.getStartLine();
|
587 | 595 | excAttrs[SyntaxErrorBuiltins.IDX_OFFSET] = section.getStartColumn();
|
588 | 596 | // Not very nice. This counts on the implementation in traceback.py where if the value of
|
589 | 597 | // text attribute is NONE, then the line is not printed
|
590 |
| - final TruffleString text = section.isAvailable() ? toTruffleStringUncached(source.getCharacters(section.getStartLine()).toString()) : null; |
| 598 | + Object text = PNone.NONE; |
| 599 | + if (section.isAvailable()) { |
| 600 | + text = toTruffleStringUncached(source.getCharacters(section.getStartLine()).toString()); |
| 601 | + } |
591 | 602 | excAttrs[SyntaxErrorBuiltins.IDX_MSG] = message;
|
592 | 603 | excAttrs[SyntaxErrorBuiltins.IDX_TEXT] = text;
|
593 | 604 | instance.setExceptionAttributes(excAttrs);
|
|
0 commit comments