implements PR008

This commit is contained in:
2026-03-24 13:42:20 +00:00
parent b4887afacb
commit b84d4c29f6
6 changed files with 1979 additions and 0 deletions
@@ -6,6 +6,7 @@ import p.studio.compiler.pbs.ast.PbsAst;
import p.studio.compiler.pbs.lexer.PbsLexer;
import p.studio.compiler.pbs.parser.PbsParser;
import p.studio.compiler.pbs.semantics.PbsDeclarationSemanticsValidator;
import p.studio.compiler.pbs.semantics.PbsFlowSemanticsValidator;
import p.studio.compiler.source.diagnostics.DiagnosticSink;
import p.studio.compiler.source.identifiers.FileId;
import p.studio.utilities.structures.ReadOnlyList;
@@ -14,6 +15,7 @@ import java.util.ArrayList;
public final class PbsFrontendCompiler {
private final PbsDeclarationSemanticsValidator declarationSemanticsValidator = new PbsDeclarationSemanticsValidator();
private final PbsFlowSemanticsValidator flowSemanticsValidator = new PbsFlowSemanticsValidator();
public IRBackendFile compileFile(
final FileId fileId,
@@ -29,6 +31,7 @@ public final class PbsFrontendCompiler {
final PbsAst.File ast,
final DiagnosticSink diagnostics) {
declarationSemanticsValidator.validate(ast, diagnostics);
flowSemanticsValidator.validate(ast, diagnostics);
return new IRBackendFile(fileId, lowerFunctions(fileId, ast));
}
@@ -13,4 +13,25 @@ public enum PbsSemanticsErrors {
E_SEM_MISSING_CONST_TYPE_ANNOTATION,
E_SEM_MISSING_CONST_INITIALIZER,
E_SEM_INVALID_RETURN_INSIDE_CTOR,
E_SEM_APPLY_NON_CALLABLE_TARGET,
E_SEM_APPLY_UNRESOLVED_OVERLOAD,
E_SEM_APPLY_AMBIGUOUS_OVERLOAD,
E_SEM_BARE_METHOD_EXTRACTION,
E_SEM_INVALID_MEMBER_ACCESS,
E_SEM_IF_NON_BOOL_CONDITION,
E_SEM_IF_BRANCH_TYPE_MISMATCH,
E_SEM_SWITCH_SELECTOR_INVALID,
E_SEM_SWITCH_PATTERN_TYPE_MISMATCH,
E_SEM_SWITCH_DUPLICATE_PATTERN,
E_SEM_SWITCH_ARM_TYPE_MISMATCH,
E_SEM_SWITCH_NON_EXHAUSTIVE,
E_SEM_WHILE_NON_BOOL_CONDITION,
E_SEM_FOR_TYPE_MISMATCH,
E_SEM_NONE_WITHOUT_EXPECTED_OPTIONAL,
E_SEM_ELSE_NON_OPTIONAL_LEFT,
E_SEM_ELSE_FALLBACK_TYPE_MISMATCH,
E_SEM_RESULT_PROPAGATE_NON_RESULT,
E_SEM_RESULT_PROPAGATE_ERROR_MISMATCH,
E_SEM_HANDLE_NON_RESULT,
E_SEM_HANDLE_ERROR_MISMATCH,
}