added improvements
This commit is contained in:
+9
-27
@@ -15,7 +15,11 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
||||
private final PbsFrontendCompiler frontendCompiler = new PbsFrontendCompiler();
|
||||
|
||||
@Override
|
||||
public IRBackend compile(final FrontendPhaseContext ctx, final LogAggregator logs, final BuildingIssueSink issues) {
|
||||
public IRBackend compile(
|
||||
final FrontendPhaseContext ctx,
|
||||
final DiagnosticSink diagnostics,
|
||||
final LogAggregator logs,
|
||||
final BuildingIssueSink issues) {
|
||||
final MutableList<IRFunction> functions = MutableList.create();
|
||||
|
||||
for (final var pId : ctx.stack.reverseTopologicalOrder) {
|
||||
@@ -26,14 +30,10 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
||||
switch (sourceHandle.getExtension()) {
|
||||
case "pbs": {
|
||||
sourceHandle.readUtf8().ifPresentOrElse(
|
||||
utf8Content -> {
|
||||
final var diagnostics = DiagnosticSink.empty();
|
||||
functions.addAll(frontendCompiler
|
||||
.compileFile(fId, utf8Content, diagnostics)
|
||||
.stream()
|
||||
.toList());
|
||||
adaptDiagnostics(sourceHandle.getCanonPath().toString(), diagnostics, issues);
|
||||
},
|
||||
utf8Content -> functions.addAll(frontendCompiler
|
||||
.compileFile(fId, utf8Content, diagnostics)
|
||||
.stream()
|
||||
.toList()),
|
||||
() -> issues.report(builder -> builder
|
||||
.error(true)
|
||||
.message("Failed to read file content: %s".formatted(sourceHandle.toString()))));
|
||||
@@ -51,22 +51,4 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
||||
.functions(functions.toReadOnlyList())
|
||||
.build();
|
||||
}
|
||||
|
||||
private void adaptDiagnostics(
|
||||
final String sourceLabel,
|
||||
final DiagnosticSink diagnostics,
|
||||
final BuildingIssueSink issues) {
|
||||
for (final var diagnostic : diagnostics) {
|
||||
final var span = diagnostic.getSpan();
|
||||
issues.report(builder -> builder
|
||||
.error(diagnostic.getSeverity().isError())
|
||||
.message("[%s] %s at %s:[%d,%d)"
|
||||
.formatted(
|
||||
diagnostic.getCode(),
|
||||
diagnostic.getMessage(),
|
||||
sourceLabel,
|
||||
span.getStart(),
|
||||
span.getEnd())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user