Add MCP compatibility ledger tool and first-pass Go/Rust codegen hardening
This commit is contained in:
@@ -13,7 +13,18 @@ public:
|
||||
std::string commentPrefix() const { return "// "; }
|
||||
|
||||
std::string generate(const ASTNode* node) override {
|
||||
return dispatchGenerate(this, node, "// Unknown concept: ");
|
||||
std::string code = dispatchGenerate(this, node, "// Unknown concept: ");
|
||||
// When the root node is a bare function, emit a legal Go translation unit.
|
||||
if (node && node->conceptType == "Function") {
|
||||
std::ostringstream wrapped;
|
||||
wrapped << "package generated\n\n";
|
||||
if (code.find("fmt.") != std::string::npos) {
|
||||
wrapped << "import \"fmt\"\n\n";
|
||||
}
|
||||
wrapped << code;
|
||||
return wrapped.str();
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
std::string visitModule(const Module* module) override {
|
||||
@@ -104,6 +115,7 @@ public:
|
||||
std::string typeStr;
|
||||
auto type = parameter->getChild("type");
|
||||
if (type) typeStr = generate(type);
|
||||
if (typeStr.empty()) typeStr = "string";
|
||||
oss << parameter->name;
|
||||
if (!typeStr.empty()) {
|
||||
oss << " " << typeStr;
|
||||
|
||||
@@ -102,6 +102,8 @@ public:
|
||||
auto type = parameter->getChild("type");
|
||||
if (type) {
|
||||
oss << ": " << generate(type);
|
||||
} else {
|
||||
oss << ": &str";
|
||||
}
|
||||
auto defaultValue = parameter->getChild("defaultValue");
|
||||
if (defaultValue) {
|
||||
@@ -266,8 +268,31 @@ public:
|
||||
|
||||
std::string visitFunctionCall(const FunctionCall* call) override {
|
||||
std::ostringstream oss;
|
||||
oss << call->functionName << "(";
|
||||
const std::string& rawName = call->functionName;
|
||||
const bool hasMacroBang = !rawName.empty() && rawName.back() == '!';
|
||||
const std::string baseName = hasMacroBang ? rawName.substr(0, rawName.size() - 1) : rawName;
|
||||
auto arguments = call->getChildren("arguments");
|
||||
if (baseName == "print" || baseName == "println") {
|
||||
oss << baseName << "!(";
|
||||
if (arguments.empty()) {
|
||||
// print!()/println!() with no args is valid.
|
||||
} else if (arguments.size() == 1) {
|
||||
const std::string arg = generate(arguments[0]);
|
||||
if (isQuotedLiteral(arg)) {
|
||||
oss << arg;
|
||||
} else {
|
||||
oss << "\"{}\", " << arg;
|
||||
}
|
||||
} else {
|
||||
for (size_t i = 0; i < arguments.size(); ++i) {
|
||||
if (i > 0) oss << ", ";
|
||||
oss << generate(arguments[i]);
|
||||
}
|
||||
}
|
||||
oss << ")";
|
||||
return oss.str();
|
||||
}
|
||||
oss << rawName << "(";
|
||||
for (size_t i = 0; i < arguments.size(); ++i) {
|
||||
if (i > 0) oss << ", ";
|
||||
oss << generate(arguments[i]);
|
||||
|
||||
Reference in New Issue
Block a user