}\r
\r
static Program globalPrg;\r
+static std::shared_ptr<Context> globalCtx;\r
\r
std::ostream & operator<< (std::ostream & out, const Type & t)\r
{\r
+ TypeInfo ti = typeType(globalPrg, t);\r
+ if (ti.isStruct)\r
+ out << "struct ";\r
out << vectorStr(t.namespacePrefixes, "_", true) << t.name;\r
\r
return out;\r
}\r
std::ostream & operator<< (std::ostream & out, const Body & b)\r
{\r
+ b.ctx->parent = globalCtx;\r
+ globalCtx = b.ctx;\r
+\r
indent(out);\r
out << "{\n";\r
indentation += 2;\r
indent(out, -2);\r
out << "}\n";\r
\r
+ globalCtx = b.ctx->parent;\r
+\r
return out;\r
}\r
std::ostream & operator<< (std::ostream & out, const Expr & e)\r
switch (e.type)\r
{\r
case ExprType::Func:\r
+ {\r
+ if (e._func.namespacePrefixes.empty())\r
+ {\r
+ TypeInfo ti = typeExpr(globalPrg, namespaces, globalCtx, e);\r
+ \r
+ }\r
out << vectorStr(e._func.namespacePrefixes, "_", true) << e._func.functionName << "(" << vectorStr(e._func.arguments, ", ") << ")"; break;\r
+ }\r
case ExprType::Method:\r
{\r
- TypeInfo ti = typeExpr(globalPrg, namespaces, *e._method.expr);\r
+ TypeInfo ti = typeExpr(globalPrg, namespaces, globalCtx, *e._method.expr);\r
out <<\r
vectorStr(ti.type.namespacePrefixes, "_", true) <<\r
- ti.type.name << "_" << e._method.methodName << "(" << *e._method.expr << vectorStr(e._method.arguments, ", ") << ")"; break;\r
+ ti.type.name << "_" << e._method.methodName <<\r
+ "(&" << *e._method.expr << (e._method.arguments.empty() ? "" : ", ") <<\r
+ vectorStr(e._method.arguments, ", ") << ")"; break;\r
}\r
case ExprType::Lit:\r
/**/ if (e._lit.type == LitType::Int) out << e._lit._int;\r
\r
void tocFunction (std::ostream & out, const Function & f, bool stub)\r
{\r
+ if (!stub && !f.defined) return;\r
+\r
out << f.returnType << " " << namespacePrefix() << f.name << " (" << vectorStr(f.parameters, ", ") << ")";\r
\r
if (stub)\r
}\r
void tocProgram (std::ostream & out, const Program & p)\r
{\r
+ globalCtx = p.ctx;\r
+\r
globalPrg = p;\r
for (auto n : p.namespaces)\r
{\r
tocNamespace(out, n, true);\r
}\r
+ out << "\n\n";\r
for (auto s : p.structs)\r
{\r
tocStruct(out, s, true);\r
}\r
+ out << "\n\n";\r
for (auto f : p.functions)\r
{\r
tocFunction(out, f, true);\r
}\r
+ out << "\n\n";\r
\r
for (auto v : p.ctx->variables)\r
{\r
out << v << ";\n";\r
}\r
+ out << "\n\n";\r
for (auto n : p.namespaces)\r
{\r
tocNamespace(out, n, false);\r
}\r
+ out << "\n\n";\r
for (auto s : p.structs)\r
{\r
tocStruct(out, s, false);\r
}\r
+ out << "\n\n";\r
for (auto f : p.functions)\r
{\r
tocFunction(out, f, false);\r
}\r
+ out << "\n\n";\r
}\r
\r
\r
void tocNamespace (std::ostream & out, const Namespace & n, bool stub)\r
{\r
+ n.ctx->parent = globalCtx;\r
+ globalCtx = n.ctx;\r
+\r
namespaces.push_back(n.name);\r
if (!stub)\r
{\r
{\r
out << v << ";\n";\r
}\r
+ out << "\n\n";\r
}\r
for (auto n : n.namespaces)\r
{\r
tocNamespace(out, n, stub);\r
+ out << "\n\n";\r
}\r
for (auto s : n.structs)\r
{\r
tocStruct(out, s, stub);\r
+ out << "\n\n";\r
}\r
for (auto f : n.functions)\r
{\r
tocFunction(out, f, stub);\r
+ out << "\n\n";\r
}\r
namespaces.pop_back();\r
+\r
+ globalCtx = n.ctx->parent;\r
}
\ No newline at end of file