]> gitweb.ps.run Git - toc/blobdiff - src/toc.h
function resolution, pre generics
[toc] / src / toc.h
index 43ab1bad3831c508f50cf83868003b342d8860e8..c0c73f155d5c86f75accb2549fa0b9c95c21ec57 100644 (file)
--- a/src/toc.h
+++ b/src/toc.h
@@ -54,9 +54,13 @@ static std::string namespacePrefix() {
 }\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
@@ -92,6 +96,9 @@ std::ostream & operator<< (std::ostream & out, const Variable & v)
 }\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
@@ -113,6 +120,8 @@ std::ostream & operator<< (std::ostream & out, const Body & b)
   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
@@ -120,13 +129,22 @@ std::ostream & operator<< (std::ostream & out, const Expr & e)
   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
@@ -196,6 +214,8 @@ std::ostream & operator<< (std::ostream & out, const Stmt & s)
 \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
@@ -265,41 +285,53 @@ void tocStruct (std::ostream & out, const Struct & s, bool stub)
 }\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
@@ -307,18 +339,24 @@ void tocNamespace  (std::ostream & out, const Namespace & n, bool stub)
     {\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