small code improvements

This commit is contained in:
2026-03-24 13:42:16 +00:00
parent 956d3128a9
commit f3be4f7946
8 changed files with 72 additions and 28 deletions
@@ -2,6 +2,7 @@ package p.studio.compiler.models;
import lombok.Builder;
import lombok.Getter;
import p.studio.utilities.structures.MutableList;
import p.studio.utilities.structures.ReadOnlyList;
@Builder
@@ -10,9 +11,28 @@ public class IRBackend {
@Builder.Default
private final ReadOnlyList<IRFunction> functions = ReadOnlyList.empty();
/**
* Returns a stable human-readable representation useful for debug logs and tests.
*/
public static IRBackendAggregator aggregator() {
return new IRBackendAggregator();
}
public static final class IRBackendAggregator {
private final MutableList<IRFunction> functions = MutableList.create();
public void merge(final IRBackendFile backendFile) {
if (backendFile == null) {
return;
}
functions.addAll(backendFile.functions());
}
public IRBackend emit() {
return IRBackend
.builder()
.functions(functions.toReadOnlyList())
.build();
}
}
@Override
public String toString() {
final var sb = new StringBuilder();
@@ -0,0 +1,19 @@
package p.studio.compiler.models;
import p.studio.compiler.source.identifiers.FileId;
import p.studio.utilities.structures.ReadOnlyList;
import java.util.Objects;
public record IRBackendFile(
FileId fileId,
ReadOnlyList<IRFunction> functions) {
public IRBackendFile {
fileId = Objects.requireNonNull(fileId, "fileId");
functions = functions == null ? ReadOnlyList.empty() : functions;
}
public static IRBackendFile empty(final FileId fileId) {
return new IRBackendFile(fileId, ReadOnlyList.empty());
}
}