Skip to content

Commit 51e7586

Browse files
committed
Port PIncompleteSourceException to the new API
1 parent 3ec2627 commit 51e7586

File tree

1 file changed

+49
-22
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime

1 file changed

+49
-22
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonParser.java

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@
3030
import com.oracle.graal.python.nodes.ErrorMessages;
3131
import com.oracle.graal.python.nodes.PNode;
3232
import com.oracle.graal.python.util.PythonUtils;
33-
import com.oracle.truffle.api.TruffleException;
33+
import com.oracle.truffle.api.exception.AbstractTruffleException;
3434
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;
3539
import com.oracle.truffle.api.nodes.Node;
3640
import com.oracle.truffle.api.nodes.RootNode;
3741
import com.oracle.truffle.api.source.Source;
@@ -137,45 +141,68 @@ default RuntimeException raiseInvalidSyntax(Source source, SourceSection section
137141
/**
138142
* Runtime exception used to indicate incomplete source code during parsing.
139143
*/
140-
public static class PIncompleteSourceException extends RuntimeException implements TruffleException {
144+
@ExportLibrary(InteropLibrary.class)
145+
class PIncompleteSourceException extends AbstractTruffleException {
141146

142147
private static final long serialVersionUID = 4393080397807767467L;
143148

144149
private Source source;
145150
private final int line;
146151

147152
public PIncompleteSourceException(String message, Throwable cause, int line) {
148-
super(message, cause);
153+
super(message, cause, UNLIMITED_STACK_TRACE, null);
149154
this.line = line;
150155
}
151156

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;
165159
}
166160

167-
@Override
168-
public boolean isSyntaxError() {
161+
@ExportMessage
162+
@SuppressWarnings("static-method")
163+
boolean isException() {
169164
return true;
170165
}
171166

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() {
174180
return true;
175181
}
176182

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();
179206
}
180207
}
181208
}

0 commit comments

Comments
 (0)