|
30 | 30 | import com.oracle.graal.python.nodes.ErrorMessages;
|
31 | 31 | import com.oracle.graal.python.nodes.PNode;
|
32 | 32 | import com.oracle.graal.python.util.PythonUtils;
|
33 |
| -import com.oracle.truffle.api.TruffleException; |
| 33 | +import com.oracle.truffle.api.exception.AbstractTruffleException; |
34 | 34 | import com.oracle.truffle.api.frame.Frame;
|
| 35 | +import com.oracle.truffle.api.interop.ExceptionType; |
| 36 | +import com.oracle.truffle.api.interop.InteropLibrary; |
| 37 | +import com.oracle.truffle.api.library.ExportLibrary; |
| 38 | +import com.oracle.truffle.api.library.ExportMessage; |
35 | 39 | import com.oracle.truffle.api.nodes.Node;
|
36 | 40 | import com.oracle.truffle.api.nodes.RootNode;
|
37 | 41 | import com.oracle.truffle.api.source.Source;
|
@@ -137,45 +141,68 @@ default RuntimeException raiseInvalidSyntax(Source source, SourceSection section
|
137 | 141 | /**
|
138 | 142 | * Runtime exception used to indicate incomplete source code during parsing.
|
139 | 143 | */
|
140 |
| - public static class PIncompleteSourceException extends RuntimeException implements TruffleException { |
| 144 | + @ExportLibrary(InteropLibrary.class) |
| 145 | + class PIncompleteSourceException extends AbstractTruffleException { |
141 | 146 |
|
142 | 147 | private static final long serialVersionUID = 4393080397807767467L;
|
143 | 148 |
|
144 | 149 | private Source source;
|
145 | 150 | private final int line;
|
146 | 151 |
|
147 | 152 | public PIncompleteSourceException(String message, Throwable cause, int line) {
|
148 |
| - super(message, cause); |
| 153 | + super(message, cause, UNLIMITED_STACK_TRACE, null); |
149 | 154 | this.line = line;
|
150 | 155 | }
|
151 | 156 |
|
152 |
| - @Override |
153 |
| - public Node getLocation() { |
154 |
| - if (line <= 0 || line > source.getLineCount()) { |
155 |
| - return null; |
156 |
| - } else { |
157 |
| - SourceSection section = source.createSection(line); |
158 |
| - return new Node() { |
159 |
| - @Override |
160 |
| - public SourceSection getSourceSection() { |
161 |
| - return section; |
162 |
| - } |
163 |
| - }; |
164 |
| - } |
| 157 | + public void setSource(Source source) { |
| 158 | + this.source = source; |
165 | 159 | }
|
166 | 160 |
|
167 |
| - @Override |
168 |
| - public boolean isSyntaxError() { |
| 161 | + @ExportMessage |
| 162 | + @SuppressWarnings("static-method") |
| 163 | + boolean isException() { |
169 | 164 | return true;
|
170 | 165 | }
|
171 | 166 |
|
172 |
| - @Override |
173 |
| - public boolean isIncompleteSource() { |
| 167 | + @ExportMessage |
| 168 | + RuntimeException throwException() { |
| 169 | + throw this; |
| 170 | + } |
| 171 | + |
| 172 | + @ExportMessage |
| 173 | + @SuppressWarnings("static-method") |
| 174 | + ExceptionType getExceptionType() { |
| 175 | + return ExceptionType.PARSE_ERROR; |
| 176 | + } |
| 177 | + |
| 178 | + @ExportMessage |
| 179 | + boolean isExceptionIncompleteSource() { |
174 | 180 | return true;
|
175 | 181 | }
|
176 | 182 |
|
177 |
| - public void setSource(Source source) { |
178 |
| - this.source = source; |
| 183 | + @ExportMessage |
| 184 | + @SuppressWarnings("static-method") |
| 185 | + boolean hasExceptionMessage() { |
| 186 | + return true; |
| 187 | + } |
| 188 | + |
| 189 | + @ExportMessage |
| 190 | + String getExceptionMessage() { |
| 191 | + return getMessage(); |
| 192 | + } |
| 193 | + |
| 194 | + @ExportMessage |
| 195 | + @SuppressWarnings("static-method") |
| 196 | + boolean hasSourceLocation() { |
| 197 | + return true; |
| 198 | + } |
| 199 | + |
| 200 | + @ExportMessage(name = "getSourceLocation") |
| 201 | + SourceSection getExceptionSourceLocation() { |
| 202 | + if (line > 0 && line < source.getLineCount()) { |
| 203 | + return source.createSection(line); |
| 204 | + } |
| 205 | + return source.createUnavailableSection(); |
179 | 206 | }
|
180 | 207 | }
|
181 | 208 | }
|
0 commit comments