+static std::vector<std::string> namespaces;\r
+static std::string namespacePrefix() {\r
+ std::stringstream sstr;\r
+ for (auto n : namespaces)\r
+ {\r
+ sstr << n << "_";\r
+ }\r
+ return sstr.str();\r
+}\r
+\r
+// mapping from generic typenames (which are just names)\r
+// to actual instantiated types\r
+static std::map<std::string, Type> currentInstantiation;\r
+\r
+// set current context so that lookups can be made correctly\r
+static std::shared_ptr<Context> globalCtx;\r
+\r
+\r
+std::ostream & operator<< (std::ostream & out, const Type & t)\r
+{\r
+ // if the typename equals one of the current generic instantiations\r
+ // print instantiated type instead\r
+ for (auto kv : currentInstantiation)\r
+ {\r
+ if (t.name == kv.first)\r
+ {\r
+ out << kv.second;\r
+ return out;\r
+ }\r
+ }\r
+ TypeInfo ti = typeType(globalCtx, t);\r
+ if (ti.isStruct)\r
+ out << "struct ";\r
+ // try finding type in current context\r
+ auto s = findStruct(t.name, t.namespacePrefixes, globalCtx);\r
+ // print prefix for either found type or the specified \r
+ // prefix if type is not found (shouldn't happen)\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
+\r
+ // print generic appendix\r
+ if (!t.genericInstantiation.empty())\r
+ out << genericAppendix(t.genericInstantiation);\r