Files
whetstone_DSL/editor/src/ConstrainedProjectionGate.h
Bill de5bdd358f Close all 26 generator readiness gaps (sprints 267-270)
Sprint 268: GR-002/003/006/007/008/016/017/019/021/024 — self-containment,
  graduation thresholds, asm/ir/jvm/elixir lang coverage, semanno format.
Sprint 269: GR-005/011/013/015 — prose capture in RequirementsParser,
  GateEnforcer, ParitySkewAnalyzer, CrossArtifactConsistencyEngine.
Sprint 270: GR-009/010/012/014/018/020 — CrossFileTransactionGate,
  SemanticCompletionGate, ConstrainedProjectionGate, TokenBudgetGate,
  CppConstraintRefactorPolicy, NativeDecompositionDepthGuard.
All 50 new tests passing (steps 1873-1882, 5/5 per step).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 22:28:41 -07:00

43 lines
1.5 KiB
C++

#pragma once
// Step 1878: Constrained projection gate.
// Closes GR-012: ProjectionGenerator.generate() has no access to EnvironmentSpec,
// so generators emit code without checking environment constraints. This gate runs
// validateCapabilities + validateEnvAnnotations before generation and blocks on errors.
#include "EnvironmentSpec.h"
#include "ast/ASTNode.h"
#include <string>
#include <vector>
struct ProjectionConstraintResult {
bool blocked = false;
std::vector<CapabilityDiagnostic> diagnostics;
};
class ConstrainedProjectionGate {
public:
// Validate the AST node against the given environment before generation.
// Returns blocked=true when any "error" severity diagnostic is found.
// A null env means no constraints — always passes.
static ProjectionConstraintResult validate(const ASTNode* node,
const EnvironmentSpec* env) {
ProjectionConstraintResult result;
if (!env) return result; // no env = no constraints
auto capDiags = validateCapabilities(node, env);
auto annDiags = validateEnvAnnotations(node, env);
for (const auto& d : capDiags) result.diagnostics.push_back(d);
for (const auto& d : annDiags) result.diagnostics.push_back(d);
for (const auto& d : result.diagnostics) {
if (d.severity == "error") {
result.blocked = true;
break;
}
}
return result;
}
};