added improvements
This commit is contained in:
parent
d55ec48707
commit
956d3128a9
@ -15,7 +15,11 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
|||||||
private final PbsFrontendCompiler frontendCompiler = new PbsFrontendCompiler();
|
private final PbsFrontendCompiler frontendCompiler = new PbsFrontendCompiler();
|
||||||
|
|
||||||
@Override
|
@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();
|
final MutableList<IRFunction> functions = MutableList.create();
|
||||||
|
|
||||||
for (final var pId : ctx.stack.reverseTopologicalOrder) {
|
for (final var pId : ctx.stack.reverseTopologicalOrder) {
|
||||||
@ -26,14 +30,10 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
|||||||
switch (sourceHandle.getExtension()) {
|
switch (sourceHandle.getExtension()) {
|
||||||
case "pbs": {
|
case "pbs": {
|
||||||
sourceHandle.readUtf8().ifPresentOrElse(
|
sourceHandle.readUtf8().ifPresentOrElse(
|
||||||
utf8Content -> {
|
utf8Content -> functions.addAll(frontendCompiler
|
||||||
final var diagnostics = DiagnosticSink.empty();
|
|
||||||
functions.addAll(frontendCompiler
|
|
||||||
.compileFile(fId, utf8Content, diagnostics)
|
.compileFile(fId, utf8Content, diagnostics)
|
||||||
.stream()
|
.stream()
|
||||||
.toList());
|
.toList()),
|
||||||
adaptDiagnostics(sourceHandle.getCanonPath().toString(), diagnostics, issues);
|
|
||||||
},
|
|
||||||
() -> issues.report(builder -> builder
|
() -> issues.report(builder -> builder
|
||||||
.error(true)
|
.error(true)
|
||||||
.message("Failed to read file content: %s".formatted(sourceHandle.toString()))));
|
.message("Failed to read file content: %s".formatted(sourceHandle.toString()))));
|
||||||
@ -51,22 +51,4 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
|||||||
.functions(functions.toReadOnlyList())
|
.functions(functions.toReadOnlyList())
|
||||||
.build();
|
.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())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import p.studio.compiler.FrontendRegistryService;
|
|||||||
import p.studio.compiler.messages.BuildingIssueSink;
|
import p.studio.compiler.messages.BuildingIssueSink;
|
||||||
import p.studio.compiler.messages.FrontendPhaseContext;
|
import p.studio.compiler.messages.FrontendPhaseContext;
|
||||||
import p.studio.compiler.models.BuilderPipelineContext;
|
import p.studio.compiler.models.BuilderPipelineContext;
|
||||||
|
import p.studio.compiler.source.diagnostics.DiagnosticSink;
|
||||||
import p.studio.compiler.workspaces.PipelineStage;
|
import p.studio.compiler.workspaces.PipelineStage;
|
||||||
import p.studio.utilities.logs.LogAggregator;
|
import p.studio.utilities.logs.LogAggregator;
|
||||||
|
|
||||||
@ -23,10 +24,28 @@ public class FrontendPhasePipelineStage implements PipelineStage {
|
|||||||
final var projectTable = ctx.resolvedWorkspace.graph().projectTable();
|
final var projectTable = ctx.resolvedWorkspace.graph().projectTable();
|
||||||
final var fileTable = ctx.fileTable;
|
final var fileTable = ctx.fileTable;
|
||||||
final var frontendPhaseContext = new FrontendPhaseContext(projectTable, fileTable, ctx.resolvedWorkspace.stack());
|
final var frontendPhaseContext = new FrontendPhaseContext(projectTable, fileTable, ctx.resolvedWorkspace.stack());
|
||||||
|
final var diagnostics = DiagnosticSink.empty();
|
||||||
final var issues = BuildingIssueSink.empty();
|
final var issues = BuildingIssueSink.empty();
|
||||||
ctx.irBackend = service.get().compile(frontendPhaseContext, logs, issues);
|
ctx.irBackend = service.get().compile(frontendPhaseContext, diagnostics, logs, issues);
|
||||||
logs.using(log).debug("IR Backend: " + ctx.irBackend);
|
logs.using(log).debug("IR Backend: " + ctx.irBackend);
|
||||||
logs.using(log).debug("Frontend phase completed successfully!");
|
logs.using(log).debug("Frontend phase completed successfully!");
|
||||||
|
adaptDiagnostics(diagnostics, issues);
|
||||||
return issues;
|
return issues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void adaptDiagnostics(
|
||||||
|
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("[BUILD] %s :: %s @ %s:[%d,%d)".formatted(
|
||||||
|
diagnostic.getCode(),
|
||||||
|
diagnostic.getMessage(),
|
||||||
|
span.getFileId(),
|
||||||
|
span.getStart(),
|
||||||
|
span.getEnd())));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,8 +3,13 @@ package p.studio.compiler.services;
|
|||||||
import p.studio.compiler.messages.BuildingIssueSink;
|
import p.studio.compiler.messages.BuildingIssueSink;
|
||||||
import p.studio.compiler.messages.FrontendPhaseContext;
|
import p.studio.compiler.messages.FrontendPhaseContext;
|
||||||
import p.studio.compiler.models.IRBackend;
|
import p.studio.compiler.models.IRBackend;
|
||||||
|
import p.studio.compiler.source.diagnostics.DiagnosticSink;
|
||||||
import p.studio.utilities.logs.LogAggregator;
|
import p.studio.utilities.logs.LogAggregator;
|
||||||
|
|
||||||
public interface FrontendPhaseService {
|
public interface FrontendPhaseService {
|
||||||
IRBackend compile(FrontendPhaseContext request, LogAggregator logs, BuildingIssueSink empty);
|
IRBackend compile(
|
||||||
|
FrontendPhaseContext request,
|
||||||
|
DiagnosticSink diagnostics,
|
||||||
|
LogAggregator logs,
|
||||||
|
BuildingIssueSink issues);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user