static Program globalPrg;\r
static std::shared_ptr<Context> globalCtx;\r
\r
+\r
+\r
+// std::string getPrefix(std::shared_ptr<Context> ctx)\r
+// {\r
+// std::string result;\r
+// for (auto it = ctx; it != nullptr; it = it->parent)\r
+// {\r
+// if (it->name.has_value())\r
+// {\r
+// result = it->name.value() + "_" + result;\r
+// }\r
+// }\r
+// return result;\r
+// }\r
+\r
std::ostream & operator<< (std::ostream & out, const Type & t)\r
{\r
for (auto kv : currentInstantiation)\r
TypeInfo ti = typeType(globalPrg, t);\r
if (ti.isStruct)\r
out << "struct ";\r
- out << vectorStr(t.namespacePrefixes, "_", true) << t.name;\r
+ auto s = findStruct(t.name, t.namespacePrefixes, globalCtx);\r
+ if (s.has_value())\r
+ out << vectorStr(std::get<1>(*s), "_", true) << t.name; \r
+ else\r
+ out << vectorStr(t.namespacePrefixes, "_", true) << t.name;\r
if (!t.genericInstantiation.empty())\r
out << genericAppendix(t.genericInstantiation);\r
\r
\r
std::stringstream sstr;\r
std::string s = v.name;\r
+ \r
+ auto var = findVariable(v.name, namespaces, globalCtx);\r
+ if (var.has_value())\r
+ s = vectorStr(std::get<1>(*var), "_", true) + s;\r
\r
for (auto m = v.type.modifiers.rbegin(); m != v.type.modifiers.rend(); m++)\r
{\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;\r
+ auto f = findFunction(e._func.functionName, e._func.namespacePrefixes, globalCtx);\r
+\r
+ if (std::get<0>(*f).defined)\r
+ out << vectorStr(std::get<1>(*f), "_", true);\r
+\r
+ out << e._func.functionName;\r
if (!e._func.genericInstantiation.empty())\r
out << genericAppendix(e._func.genericInstantiation);\r
out <<"(" << vectorStr(e._func.arguments, ", ") << ")"; break;\r
}\r
case ExprType::Method:\r
{\r
- TypeInfo ti = typeExpr(globalPrg, namespaces, globalCtx, *e._method.expr);\r
+ TypeInfo ti = typeExpr(globalPrg, globalCtx, *e._method.expr);\r
out <<\r
vectorStr(ti.type.namespacePrefixes, "_", true) <<\r
ti.type.name << genericAppendix(ti.type.genericInstantiation) << "_" << e._method.methodName;\r
case ExprType::Bracket:\r
out << *e._brackets.lexpr << "[" << *e._brackets.rexpr << "]"; break;\r
case ExprType::Identifier:\r
- out << vectorStr(e._identifier.namespacePrefixes, "_", true) << e._identifier.identifier; break;\r
+ auto v = findVariable(e._identifier.identifier, e._identifier.namespacePrefixes, globalCtx);\r
+ if (v.has_value())\r
+ out << vectorStr(std::get<1>(*v), "_", true);\r
+ else\r
+ out << vectorStr(e._identifier.namespacePrefixes, "_", true);\r
+\r
+ out << e._identifier.identifier; break;\r
}\r
\r
return out;\r
}\r
}\r
}\r
-void tocProgram (std::ostream & out, const Program & _p)\r
+void tocProgram (std::ostream & out, const Program & p)\r
{\r
- Program p = instantiateGenerics(_p);\r
-\r
globalCtx = p.ctx;\r
\r
globalPrg = p;\r
- for (auto n : p.namespaces)\r
+ for (auto n : p.ctx->namespaces)\r
{\r
tocNamespace(out, n, true);\r
}\r
out << v << ";\n";\r
}\r
out << "\n\n";\r
- for (auto n : p.namespaces)\r
+ for (auto n : p.ctx->namespaces)\r
{\r
tocNamespace(out, n, false);\r
}\r
}\r
out << "\n\n";\r
}\r
- for (auto n : n.namespaces)\r
+ for (auto n : n.ctx->namespaces)\r
{\r
tocNamespace(out, n, stub);\r
out << "\n\n";\r