Step 308: All 8 generators produce language-appropriate output for 9 new AST node types (8/8 tests)

Phase 11c complete (80/80 tests). Added visitor implementations for
ClassDeclaration, InterfaceDeclaration, MethodDeclaration, GenericType,
TypeParameter, AsyncFunction, AwaitExpression, LambdaExpression, and
DecoratorAnnotation to Rust, Go, Java, JavaScript/TypeScript, and Elisp
generators. Each generator emits idiomatic syntax: Rust struct+impl/trait/async fn/.await/|closure|,
Go type struct/interface/func receiver/<-channel/func(), Java class extends/interface/CompletableFuture/(x)->/@annotation,
JS class extends/async function/await/(x)=>/class, Elisp cl-defstruct/cl-defgeneric/cl-defmethod/(lambda).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Bill
2026-02-15 15:08:55 +00:00
parent dc462e8941
commit a2a9fe6f97
8 changed files with 1120 additions and 0 deletions

View File

@@ -1,6 +1,9 @@
#pragma once
#include "ProjectionGenerator.h"
#include "Import.h"
#include "ClassDeclaration.h"
#include "GenericType.h"
#include "AsyncNodes.h"
#include "../SemannoAnnotationImpl.h"
class GoGenerator : public ProjectionGenerator, public SemannoAnnotationImpl<GoGenerator> {
@@ -404,6 +407,118 @@ public:
return type->typeName;
}
// --- New AST node visitors (Step 308) ---
std::string visitClassDeclaration(const ASTNode* node) override {
auto* cls = static_cast<const ClassDeclaration*>(node);
std::ostringstream oss;
auto annotations = cls->getChildren("annotations");
for (const auto* a : annotations) oss << generate(a) << "\n";
oss << "type " << cls->name << " struct {\n";
auto fields = cls->getChildren("fields");
for (const auto* f : fields)
oss << " " << generate(f) << "\n";
oss << "}\n";
auto methods = cls->getChildren("methods");
for (const auto* m : methods) oss << "\n" << generate(m);
return oss.str();
}
std::string visitInterfaceDeclaration(const ASTNode* node) override {
auto* iface = static_cast<const InterfaceDeclaration*>(node);
std::ostringstream oss;
oss << "type " << iface->name << " interface {\n";
auto methods = iface->getChildren("methods");
for (const auto* m : methods) {
auto* meth = static_cast<const MethodDeclaration*>(m);
oss << " " << meth->name << "()\n";
}
oss << "}\n";
return oss.str();
}
std::string visitMethodDeclaration(const ASTNode* node) override {
auto* meth = static_cast<const MethodDeclaration*>(node);
std::ostringstream oss;
auto annotations = meth->getChildren("annotations");
for (const auto* a : annotations) oss << generate(a) << "\n";
oss << "func ";
if (!meth->isStatic && !meth->className.empty()) {
oss << "(" << receiverVar(meth->className) << " *" << meth->className << ") ";
}
oss << meth->name << "(";
emitParameters(oss, meth->getChildren("parameters"));
oss << ")";
auto retType = meth->getChild("returnType");
if (retType) oss << " " << generate(retType);
oss << " {\n";
emitBody(oss, meth->getChildren("body"), " ");
oss << "}\n";
return oss.str();
}
std::string visitGenericType(const ASTNode* node) override {
auto* gen = static_cast<const GenericType*>(node);
std::ostringstream oss;
oss << gen->baseName << "[";
auto params = gen->getChildren("typeParameters");
for (size_t i = 0; i < params.size(); ++i) {
if (i > 0) oss << ", ";
oss << generate(params[i]);
}
oss << "]";
return oss.str();
}
std::string visitTypeParameter(const ASTNode* node) override {
auto* tp = static_cast<const TypeParameter*>(node);
if (!tp->constraint.empty()) return tp->name + " " + tp->constraint;
return tp->name;
}
std::string visitAsyncFunction(const ASTNode* node) override {
auto* af = static_cast<const AsyncFunction*>(node);
std::ostringstream oss;
auto annotations = af->getChildren("annotations");
for (const auto* a : annotations) oss << generate(a) << "\n";
oss << "func " << af->name << "(";
emitParameters(oss, af->getChildren("parameters"));
oss << ")";
auto retType = af->getChild("returnType");
if (retType) oss << " " << generate(retType);
oss << " {\n";
oss << " // async: use goroutine\n";
emitBody(oss, af->getChildren("body"), " ");
oss << "}\n";
return oss.str();
}
std::string visitAwaitExpression(const ASTNode* node) override {
auto* aw = static_cast<const AwaitExpression*>(node);
auto* expr = aw->getChild("expression");
return "<-" + (expr ? generate(expr) : "/* missing */");
}
std::string visitLambdaExpression(const ASTNode* node) override {
auto* lam = static_cast<const LambdaExpression*>(node);
std::ostringstream oss;
oss << "func(";
auto params = lam->getChildren("parameters");
for (size_t i = 0; i < params.size(); ++i) {
if (i > 0) oss << ", ";
oss << visitParameter(static_cast<const Parameter*>(params[i]));
}
oss << ") {\n";
emitBody(oss, lam->getChildren("body"), " ");
oss << "}";
return oss.str();
}
std::string visitDecoratorAnnotation(const ASTNode* node) override {
auto* dec = static_cast<const DecoratorAnnotation*>(node);
return "// @" + dec->name;
}
std::string visitDerefStrategy(const DerefStrategy* annotation) override {
return "// @deref(" + annotation->strategy + ")";
}