]> gitweb.ps.run Git - toc/blobdiff - src/toc.h
compile again
[toc] / src / toc.h
index 67f92dc0753648093a1f3b156c48cca6121b1c93..6dd611dd3035d9a9f67c5d87a1b7c797a2cc24b5 100644 (file)
--- a/src/toc.h
+++ b/src/toc.h
@@ -59,7 +59,7 @@ std::ostream & operator<< (std::ostream & out, const Body & b) {
   \r
   for (auto s : b.statements) {\r
     indent(out);\r
-    out << s << ";\n";\r
+    out << s << "\n";\r
   }\r
 \r
   indent(out, -2);\r
@@ -89,34 +89,57 @@ std::ostream & operator<< (std::ostream & out, const TernaryOperatorExpr & o) {
 }\r
 std::ostream & operator<< (std::ostream & out, const Expr & e) {\r
   switch (e.type) {\r
+  case ExprType::Func:\r
+    out << e._func.functionName << "(" << e._func.arguments << ")"; break;\r
+  case ExprType::Lit:\r
+    /**/ if (e._lit.type == LitType::Int) out << e._lit._int;\r
+    else if (e._lit.type == LitType::Decimal) out << e._lit._decimal;\r
+    else if (e._lit.type == LitType::String) out << e._lit._string;\r
+    else if (e._lit.type == LitType::Bool) out << e._lit._bool;\r
+    break;\r
+  case ExprType::Identifier:\r
+    out << e._identifier.name; break;\r
   case ExprType::Brackets:\r
     out << *e._brackets.lexpr << "[" << *e._brackets.rexpr << "]"; break;\r
-  case ExprType::Call:\r
-    out << e._call.functionName << "(" << e._call.arguments << ")"; break;\r
   case ExprType::Dot:\r
-    out << e._dot.name << "." << *e._dot.lexpr; break;\r
-  case ExprType::Literal:\r
-    out << e._literal.i; break;\r
-  case ExprType::Operator:\r
-    out << e._operator; break;\r
-  case ExprType::Variable:\r
-    out << e._variable.name; break;\r
+    out << *e._dot.expr << "." << e._dot.ident.name; break;\r
+  case ExprType::UnaryOperator:\r
+    out << e._unaryOperator; break;\r
+  case ExprType::BinaryOperator:\r
+    out << e._binaryOperator; break;\r
+  case ExprType::TernaryOperator:\r
+    out << e._ternaryOperator; break;\r
   }\r
 \r
   return out;\r
 }\r
 std::ostream & operator<< (std::ostream & out, const Stmt & s) {\r
   switch (s.type) {\r
-  case StmtType::Assign:\r
-    out << s._assign.lexpr << "=" << s._assign.rexpr; break;\r
-   case StmtType::Expr:\r
-     out << s._expr; break;\r
   case StmtType::If:\r
     out << "if (" << s._if.condition << ")\n" << s._if.body; break;\r
-  case StmtType::Return:\r
-    out << "return " << s._return.expr; break;\r
+  case StmtType::Switch:\r
+    out << "switch (" << s._switch.ident.name << ")\n{\n";\r
+    for (auto c : s._switch.cases) {\r
+      indent(out, 2);\r
+      out << "case " << *c.expr << ": " << c.body << "break;";\r
+    }\r
+    indent(out, -2);\r
+    out << "}\n";\r
+    break;\r
+  case StmtType::For:\r
+    out << "for (" <<\r
+      s._for.varName << " = " << *s._for.initValue << "; " <<\r
+      *s._for.condition << "; " <<\r
+      *s._for.action <<\r
+      ")\n" << s._for.body; break;\r
   case StmtType::While:\r
     out << "while (" << s._while.condition << ")\n" << s._while.body; break;\r
+  case StmtType::Assign:\r
+    out << s._assign.name << "=" << s._assign.expr << ";"; break;\r
+  case StmtType::Return:\r
+    out << "return " << s._return.expr << ";"; break;\r
+  case StmtType::Expr:\r
+    out << s._expr << ";"; break;\r
   }\r
 \r
   return out;\r
@@ -124,17 +147,7 @@ std::ostream & operator<< (std::ostream & out, const Stmt & s) {
 \r
 \r
 void tocFunction (std::ostream & out, const Function & f, bool stub) {\r
-  out << f.returnType << " " << f.name << " (";\r
-\r
-  bool comma = false;\r
-  for (auto p : f.parameters) {\r
-    if (comma) out << ", ";\r
-    else comma = true;\r
-\r
-    out << p.type << " " << p.name;\r
-  }\r
-\r
-  out << ")";\r
+  out << f.returnType << " " << f.name << " (" << f.parameters << ")";\r
 \r
   if (stub) {\r
     out << ";\n";\r
@@ -147,6 +160,9 @@ void tocStruct (std::ostream & out, const Struct & s, bool stub) {
   out << "struct " << s.name;\r
   if (stub) {\r
     out << ";\n";\r
+    for (auto m : s.methods) {\r
+      out << m.returnType << " " << s.name << "_" << m.name << " (" << m.parameters << ");\n";\r
+    }\r
     return;\r
   }\r
   out << "\n{\n";\r
@@ -159,6 +175,10 @@ void tocStruct (std::ostream & out, const Struct & s, bool stub) {
 \r
   indent(out, -2);\r
   out << "};\n";\r
+  \r
+  for (auto m : s.methods) {\r
+    out << m.returnType << " " << s.name << "_" << m.name << " (" << m.parameters << ")\n" << m.body;\r
+  }\r
 }\r
 void tocProgram (std::ostream & out, const Program & p) {\r
   for (auto s : p.structs) {\r