Skip to content

Commit afadec5

Browse files
committed
Reuse ErrorCallback to report warnings from parser
1 parent 7962b0d commit afadec5

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ public RootCallTarget parseForBytecodeInterpreter(PythonContext context, Source
526526
Parser parser = Compiler.createParser(source.getCharacters().toString(), errorCb, type, interactiveTerminal);
527527
ModTy mod = (ModTy) parser.parse();
528528
assert mod != null;
529-
return compileForBytecodeInterpreter(context, mod, source, topLevel, optimize, argumentNames);
529+
return compileForBytecodeInterpreter(context, mod, source, topLevel, optimize, argumentNames, errorCb);
530530
} catch (PException e) {
531531
if (topLevel) {
532532
PythonUtils.getOrCreateCallTarget(new TopLevelExceptionHandler(this, e)).call();
@@ -536,8 +536,12 @@ public RootCallTarget parseForBytecodeInterpreter(PythonContext context, Source
536536
}
537537

538538
@TruffleBoundary
539-
public RootCallTarget compileForBytecodeInterpreter(PythonContext context, ModTy mod, Source source, boolean topLevel, int optimize, List<String> argumentNames) {
540-
RaisePythonExceptionErrorCallback errorCb = new RaisePythonExceptionErrorCallback(source, PythonOptions.isPExceptionWithJavaStacktrace(this));
539+
public RootCallTarget compileForBytecodeInterpreter(PythonContext context, ModTy mod, Source source, boolean topLevel, int optimize, List<String> argumentNames,
540+
RaisePythonExceptionErrorCallback errorCallback) {
541+
RaisePythonExceptionErrorCallback errorCb = errorCallback;
542+
if (errorCb == null) {
543+
errorCb = new RaisePythonExceptionErrorCallback(source, PythonOptions.isPExceptionWithJavaStacktrace(this));
544+
}
541545
try {
542546
Compiler compiler = new Compiler(errorCb);
543547
boolean hasArguments = argumentNames != null && !argumentNames.isEmpty();
@@ -547,9 +551,9 @@ public RootCallTarget compileForBytecodeInterpreter(PythonContext context, ModTy
547551
CompilationUnit cu = compiler.compile(mod, EnumSet.noneOf(Compiler.Flags.class), optimize);
548552
CodeUnit co = cu.assemble();
549553
RootNode rootNode = PBytecodeRootNode.create(this, co, source, errorCb);
550-
GilNode gil = GilNode.getUncached();
551-
boolean wasAcquired = gil.acquire(context, rootNode);
552554
if (topLevel) {
555+
GilNode gil = GilNode.getUncached();
556+
boolean wasAcquired = gil.acquire(context, rootNode);
553557
try {
554558
errorCb.triggerDeprecationWarnings();
555559
} finally {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,7 @@ Object compile(TruffleString expression, TruffleString filename, TruffleString m
11241124
RaisePythonExceptionErrorCallback errorCb = new RaisePythonExceptionErrorCallback(source, PythonOptions.isPExceptionWithJavaStacktrace(getLanguage()));
11251125
Parser parser = Compiler.createParser(code.toJavaStringUncached(), errorCb, type, false);
11261126
ModTy mod = (ModTy) parser.parse();
1127+
errorCb.triggerDeprecationWarnings();
11271128
return AstModuleBuiltins.sst2Obj(getContext(), mod);
11281129
}
11291130
CallTarget ct;
@@ -1211,7 +1212,7 @@ Object generic(VirtualFrame frame, Object wSource, Object wFilename, Object wMod
12111212
ModTy mod = AstModuleBuiltins.obj2sst(getContext(), wSource);
12121213
// TODO _PyAST_Validate
12131214
Source source = createFakeSource();
1214-
RootCallTarget rootCallTarget = getLanguage().compileForBytecodeInterpreter(getContext(), mod, source, false, optimize, null);
1215+
RootCallTarget rootCallTarget = getLanguage().compileForBytecodeInterpreter(getContext(), mod, source, false, optimize, null, null);
12151216
return wrapRootCallTarget(rootCallTarget);
12161217
}
12171218
TruffleString source = sourceAsString(frame, wSource, filename, interopLib, acquireLib, bufferLib, handleDecodingErrorNode, asStrNode, switchEncodingNode);

0 commit comments

Comments
 (0)