Sprint 3 complete: Phases 3g+3h (Steps 68-75), all 75 steps done
Phase 3g — Optimization Pipeline (17/17 tests):
Step 68: TransformEngine — constant folding, dead code elimination, OptimizationLock warning
Step 69: StrategyAwareOptimizer — annotation-constrained (@Reclaim allows, @Owner blocks duplication, @Deallocate blocks reorder, @Allocate blocks dynamic)
Step 70: StrategyValidator — post-optimization invariants (use-after-free, leak, aliasing)
Step 71: IncrementalOptimizer — transform journal, undo by ID, provenance tracking
Phase 3h — Integration & Validation (26/26 tests):
Step 72: Pipeline — end-to-end parse→infer→validate→optimize→generate for Python/C++
Step 73: Error handling — empty ASTs, null roots, nonexistent IDs, unannotated code
Step 74: Performance benchmarks — 1000-fn AST 1ms, JSON round-trip 4ms, 50 transforms+undo 1ms
Step 75: APIDocGenerator — structured docs for 23 components across 6 categories
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 07:35:37 -07:00
|
|
|
#pragma once
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include "ast/ASTNode.h"
|
|
|
|
|
#include "ast/Module.h"
|
|
|
|
|
#include "ast/Function.h"
|
|
|
|
|
#include "ast/Annotation.h"
|
|
|
|
|
#include "ast/Parser.h"
|
|
|
|
|
#include "ast/Generator.h"
|
|
|
|
|
#include "MemoryStrategyInference.h"
|
|
|
|
|
#include "AnnotationValidator.h"
|
|
|
|
|
#include "TransformEngine.h"
|
|
|
|
|
#include "StrategyValidator.h"
|
|
|
|
|
#include "CrossLanguageProjector.h"
|
|
|
|
|
|
|
|
|
|
class Pipeline {
|
|
|
|
|
public:
|
|
|
|
|
struct PipelineResult {
|
|
|
|
|
std::unique_ptr<Module> ast;
|
|
|
|
|
std::vector<MemoryStrategyInference::Suggestion> suggestions;
|
|
|
|
|
std::vector<AnnotationValidator::Diagnostic> validationDiags;
|
|
|
|
|
std::vector<StrategyValidator::Violation> violations;
|
|
|
|
|
TransformEngine::TransformResult foldResult;
|
|
|
|
|
TransformEngine::TransformResult dceResult;
|
|
|
|
|
std::string generatedCode;
|
|
|
|
|
std::vector<ParseDiagnostic> parseDiags;
|
|
|
|
|
bool success = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Full pipeline: parse → infer → validate → optimize → generate
|
|
|
|
|
PipelineResult run(const std::string& source,
|
|
|
|
|
const std::string& sourceLanguage,
|
|
|
|
|
const std::string& targetLanguage) {
|
|
|
|
|
PipelineResult result;
|
|
|
|
|
|
|
|
|
|
// 1. Parse
|
|
|
|
|
result.ast = parse(source, sourceLanguage, result.parseDiags);
|
|
|
|
|
if (!result.ast) return result;
|
|
|
|
|
|
|
|
|
|
// 2. Infer memory annotations
|
|
|
|
|
MemoryStrategyInference inferrer;
|
|
|
|
|
result.suggestions = inferrer.inferAnnotations(result.ast.get());
|
|
|
|
|
|
|
|
|
|
// 3. Apply top suggestion as annotation (if any)
|
|
|
|
|
applyTopSuggestion(result.ast.get(), result.suggestions);
|
|
|
|
|
|
|
|
|
|
// 4. Validate annotations
|
|
|
|
|
AnnotationValidator annoValidator;
|
|
|
|
|
result.validationDiags = annoValidator.validate(result.ast.get());
|
|
|
|
|
|
|
|
|
|
// 5. Optimize (constant folding + DCE)
|
|
|
|
|
TransformEngine engine;
|
|
|
|
|
engine.setRoot(result.ast.get());
|
|
|
|
|
result.foldResult = engine.constantFolding();
|
|
|
|
|
result.dceResult = engine.deadCodeElimination();
|
|
|
|
|
|
|
|
|
|
// 6. Validate post-optimization invariants
|
|
|
|
|
StrategyValidator stratValidator;
|
|
|
|
|
result.violations = stratValidator.validateInvariants(result.ast.get());
|
|
|
|
|
|
|
|
|
|
// 7. Project to target language if different
|
|
|
|
|
Module* genSource = result.ast.get();
|
|
|
|
|
std::unique_ptr<Module> projected;
|
|
|
|
|
if (sourceLanguage != targetLanguage) {
|
|
|
|
|
CrossLanguageProjector projector;
|
|
|
|
|
projected = projector.project(result.ast.get(), targetLanguage);
|
|
|
|
|
genSource = projected.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 8. Generate code
|
|
|
|
|
result.generatedCode = generate(genSource, targetLanguage);
|
|
|
|
|
result.success = true;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parse-only step (exposed for partial pipeline use)
|
|
|
|
|
std::unique_ptr<Module> parse(const std::string& source,
|
|
|
|
|
const std::string& language,
|
|
|
|
|
std::vector<ParseDiagnostic>& diags) {
|
|
|
|
|
if (language == "python") {
|
|
|
|
|
auto pr = TreeSitterParser::parsePythonWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
|
|
|
|
} else if (language == "cpp") {
|
|
|
|
|
auto pr = TreeSitterParser::parseCppWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
2026-02-09 18:44:36 -07:00
|
|
|
} else if (language == "elisp") {
|
|
|
|
|
auto pr = TreeSitterParser::parseElispWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
|
|
|
|
} else if (language == "javascript") {
|
|
|
|
|
auto pr = TreeSitterParser::parseJavaScriptWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
|
|
|
|
} else if (language == "typescript") {
|
|
|
|
|
auto pr = TreeSitterParser::parseTypeScriptWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
2026-02-09 18:54:52 -07:00
|
|
|
} else if (language == "java") {
|
|
|
|
|
auto pr = TreeSitterParser::parseJavaWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
2026-02-09 19:02:07 -07:00
|
|
|
} else if (language == "rust") {
|
|
|
|
|
auto pr = TreeSitterParser::parseRustWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
2026-02-09 19:08:42 -07:00
|
|
|
} else if (language == "go") {
|
|
|
|
|
auto pr = TreeSitterParser::parseGoWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
2026-02-13 18:41:31 +00:00
|
|
|
} else if (language == "kotlin") {
|
Steps 309-319: Sprint 11 Phases 11d-e — Kotlin/C# languages + workflow annotation foundation
Phase 11d (Steps 309-313): Kotlin + C# parsers and generators
- KotlinParser (regex-based): fun, suspend fun, class, data class, val/var
- KotlinGenerator: idiomatic Kotlin output with type mappings
- CSharpParser (regex-based): methods, async, class, interface
- CSharpGenerator: Allman braces, foreach, Task async, LINQ types
- Pipeline integration for both languages, 10 parsers + 10 generators
Phase 11e (Steps 314-319): Workflow annotation foundation
- AnnotationInference: generalized multi-subject inference engine
- Subject 9 routing annotations: ContextWidth, Review, Ambiguity,
Automatability, Priority, ImplementationStatus
- SkeletonAST: project specification before code exists
- Architect tooling: createSkeleton, addSkeletonNode, getProjectModel,
inferAnnotations RPCs + 4 MCP tools (42+ total)
- Inference-to-routing bridge: complexity→ambiguity, getter→deterministic
- TrainingDataExporter + TrainingDataGenerator scaffolding
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 15:50:06 -07:00
|
|
|
auto pr = KotlinParser::parseKotlinWithDiagnostics(source);
|
2026-02-13 18:41:31 +00:00
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
|
|
|
|
} else if (language == "csharp") {
|
Steps 309-319: Sprint 11 Phases 11d-e — Kotlin/C# languages + workflow annotation foundation
Phase 11d (Steps 309-313): Kotlin + C# parsers and generators
- KotlinParser (regex-based): fun, suspend fun, class, data class, val/var
- KotlinGenerator: idiomatic Kotlin output with type mappings
- CSharpParser (regex-based): methods, async, class, interface
- CSharpGenerator: Allman braces, foreach, Task async, LINQ types
- Pipeline integration for both languages, 10 parsers + 10 generators
Phase 11e (Steps 314-319): Workflow annotation foundation
- AnnotationInference: generalized multi-subject inference engine
- Subject 9 routing annotations: ContextWidth, Review, Ambiguity,
Automatability, Priority, ImplementationStatus
- SkeletonAST: project specification before code exists
- Architect tooling: createSkeleton, addSkeletonNode, getProjectModel,
inferAnnotations RPCs + 4 MCP tools (42+ total)
- Inference-to-routing bridge: complexity→ambiguity, getter→deterministic
- TrainingDataExporter + TrainingDataGenerator scaffolding
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 15:50:06 -07:00
|
|
|
auto pr = CSharpParser::parseCSharpWithDiagnostics(source);
|
2026-02-13 18:41:31 +00:00
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
2026-02-16 15:22:55 -07:00
|
|
|
} else if (language == "fsharp" || language == "f#" || language == "fs") {
|
|
|
|
|
auto pr = FSharpParser::parseFSharpWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
2026-02-16 15:28:43 -07:00
|
|
|
} else if (language == "vbnet" || language == "vb" || language == "vb.net") {
|
|
|
|
|
auto pr = VBNetParser::parseVBNetWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
2026-02-16 15:40:06 -07:00
|
|
|
} else if (language == "postgresql" || language == "postgres") {
|
|
|
|
|
auto pr = PostgreSQLParser::parsePostgreSQLWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
2026-02-16 15:50:23 -07:00
|
|
|
} else if (language == "tsql" || language == "sqlserver" || language == "mssql") {
|
|
|
|
|
auto pr = TSQLParser::parseTSQLWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
2026-02-16 15:54:37 -07:00
|
|
|
} else if (language == "mysql" || language == "mariadb") {
|
|
|
|
|
auto pr = MySQLParser::parseMySQLWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
2026-02-16 09:28:14 -07:00
|
|
|
} else if (language == "c") {
|
|
|
|
|
auto pr = CParser::parseCWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
2026-02-16 09:49:50 -07:00
|
|
|
return std::move(pr.module);
|
|
|
|
|
} else if (language == "wat" || language == "wasm") {
|
|
|
|
|
auto pr = WatParser::parseWatWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
2026-02-16 09:28:14 -07:00
|
|
|
return std::move(pr.module);
|
2026-02-16 11:08:20 -07:00
|
|
|
} else if (language == "common-lisp" || language == "commonlisp" ||
|
|
|
|
|
language == "lisp" || language == "cl") {
|
|
|
|
|
auto pr = CommonLispParser::parseCommonLispWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
2026-02-16 11:30:33 -07:00
|
|
|
} else if (language == "scheme" || language == "scm") {
|
|
|
|
|
auto pr = SchemeParser::parseSchemeWithDiagnostics(source);
|
|
|
|
|
diags = std::move(pr.diagnostics);
|
|
|
|
|
return std::move(pr.module);
|
Sprint 3 complete: Phases 3g+3h (Steps 68-75), all 75 steps done
Phase 3g — Optimization Pipeline (17/17 tests):
Step 68: TransformEngine — constant folding, dead code elimination, OptimizationLock warning
Step 69: StrategyAwareOptimizer — annotation-constrained (@Reclaim allows, @Owner blocks duplication, @Deallocate blocks reorder, @Allocate blocks dynamic)
Step 70: StrategyValidator — post-optimization invariants (use-after-free, leak, aliasing)
Step 71: IncrementalOptimizer — transform journal, undo by ID, provenance tracking
Phase 3h — Integration & Validation (26/26 tests):
Step 72: Pipeline — end-to-end parse→infer→validate→optimize→generate for Python/C++
Step 73: Error handling — empty ASTs, null roots, nonexistent IDs, unannotated code
Step 74: Performance benchmarks — 1000-fn AST 1ms, JSON round-trip 4ms, 50 transforms+undo 1ms
Step 75: APIDocGenerator — structured docs for 23 components across 6 categories
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 07:35:37 -07:00
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate-only step
|
|
|
|
|
std::string generate(const ASTNode* ast, const std::string& language) {
|
|
|
|
|
if (!ast) return "";
|
|
|
|
|
if (language == "python") {
|
|
|
|
|
PythonGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
|
|
|
|
} else if (language == "cpp") {
|
|
|
|
|
CppGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
|
|
|
|
} else if (language == "elisp") {
|
|
|
|
|
ElispGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
2026-02-09 18:44:36 -07:00
|
|
|
} else if (language == "javascript") {
|
|
|
|
|
JavaScriptGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
|
|
|
|
} else if (language == "typescript") {
|
|
|
|
|
TypeScriptGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
2026-02-09 18:54:52 -07:00
|
|
|
} else if (language == "java") {
|
|
|
|
|
JavaGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
2026-02-09 19:02:07 -07:00
|
|
|
} else if (language == "rust") {
|
|
|
|
|
RustGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
2026-02-09 19:08:42 -07:00
|
|
|
} else if (language == "go") {
|
|
|
|
|
GoGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
2026-02-13 18:41:31 +00:00
|
|
|
} else if (language == "kotlin") {
|
|
|
|
|
KotlinGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
|
|
|
|
} else if (language == "csharp") {
|
|
|
|
|
CSharpGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
2026-02-16 15:26:23 -07:00
|
|
|
} else if (language == "fsharp" || language == "f#" || language == "fs") {
|
|
|
|
|
FSharpGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
2026-02-16 15:31:23 -07:00
|
|
|
} else if (language == "vbnet" || language == "vb" || language == "vb.net") {
|
|
|
|
|
VBNetGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
2026-02-16 15:45:27 -07:00
|
|
|
} else if (language == "postgresql" || language == "postgres") {
|
|
|
|
|
PostgreSQLGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
2026-02-16 15:50:23 -07:00
|
|
|
} else if (language == "tsql" || language == "sqlserver" || language == "mssql") {
|
|
|
|
|
TSQLGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
2026-02-16 15:54:37 -07:00
|
|
|
} else if (language == "mysql" || language == "mariadb") {
|
|
|
|
|
MySQLGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
2026-02-16 09:31:12 -07:00
|
|
|
} else if (language == "c") {
|
|
|
|
|
CGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
2026-02-16 09:53:33 -07:00
|
|
|
} else if (language == "wat" || language == "wasm") {
|
|
|
|
|
WatGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
2026-02-16 11:12:38 -07:00
|
|
|
} else if (language == "common-lisp" || language == "commonlisp" ||
|
|
|
|
|
language == "lisp" || language == "cl") {
|
|
|
|
|
CommonLispGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
2026-02-16 11:33:29 -07:00
|
|
|
} else if (language == "scheme" || language == "scm") {
|
|
|
|
|
SchemeGenerator gen;
|
|
|
|
|
return gen.generate(ast);
|
Sprint 3 complete: Phases 3g+3h (Steps 68-75), all 75 steps done
Phase 3g — Optimization Pipeline (17/17 tests):
Step 68: TransformEngine — constant folding, dead code elimination, OptimizationLock warning
Step 69: StrategyAwareOptimizer — annotation-constrained (@Reclaim allows, @Owner blocks duplication, @Deallocate blocks reorder, @Allocate blocks dynamic)
Step 70: StrategyValidator — post-optimization invariants (use-after-free, leak, aliasing)
Step 71: IncrementalOptimizer — transform journal, undo by ID, provenance tracking
Phase 3h — Integration & Validation (26/26 tests):
Step 72: Pipeline — end-to-end parse→infer→validate→optimize→generate for Python/C++
Step 73: Error handling — empty ASTs, null roots, nonexistent IDs, unannotated code
Step 74: Performance benchmarks — 1000-fn AST 1ms, JSON round-trip 4ms, 50 transforms+undo 1ms
Step 75: APIDocGenerator — structured docs for 23 components across 6 categories
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 07:35:37 -07:00
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void applyTopSuggestion(Module* mod,
|
|
|
|
|
const std::vector<MemoryStrategyInference::Suggestion>& suggestions) {
|
|
|
|
|
if (suggestions.empty()) return;
|
|
|
|
|
|
|
|
|
|
// Apply the module-level suggestion with highest confidence
|
|
|
|
|
for (const auto& s : suggestions) {
|
|
|
|
|
if (s.nodeId == mod->id && s.confidence >= 0.5) {
|
|
|
|
|
Annotation* anno = createAnnotation(s);
|
|
|
|
|
if (anno) {
|
|
|
|
|
mod->addChild("annotations", anno);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Annotation* createAnnotation(const MemoryStrategyInference::Suggestion& s) {
|
|
|
|
|
if (s.annotationType == "ReclaimAnnotation") {
|
|
|
|
|
auto* a = new ReclaimAnnotation();
|
|
|
|
|
a->id = "inferred_" + s.nodeId;
|
|
|
|
|
a->strategy = s.strategy;
|
|
|
|
|
return a;
|
|
|
|
|
} else if (s.annotationType == "LifetimeAnnotation") {
|
|
|
|
|
auto* a = new LifetimeAnnotation();
|
|
|
|
|
a->id = "inferred_" + s.nodeId;
|
|
|
|
|
a->strategy = s.strategy;
|
|
|
|
|
return a;
|
|
|
|
|
} else if (s.annotationType == "DeallocateAnnotation") {
|
|
|
|
|
auto* a = new DeallocateAnnotation();
|
|
|
|
|
a->id = "inferred_" + s.nodeId;
|
|
|
|
|
a->strategy = s.strategy;
|
|
|
|
|
return a;
|
|
|
|
|
} else if (s.annotationType == "OwnerAnnotation") {
|
|
|
|
|
auto* a = new OwnerAnnotation();
|
|
|
|
|
a->id = "inferred_" + s.nodeId;
|
|
|
|
|
a->strategy = s.strategy;
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
};
|