]> gitweb.ps.run Git - toc/blobdiff - src/repr_get.h
generic functions and structs
[toc] / src / repr_get.h
index 827c02bd63e27882d8ff029f59b9d189cbdacd0b..2d321b0a9bd7ef4cd7aa8e9a7f56afd7631e8464 100644 (file)
@@ -43,6 +43,13 @@ Type getType(TocParser::TypeContext * ctx)
       isStaticArray ? atoi(m->INT_LIT()->toString().c_str()) : -1\r
     );\r
   }\r
+  if (ctx->genericInstantiation() != nullptr)\r
+  {\r
+    for (auto g : ctx->genericInstantiation()->type())\r
+    {\r
+      result.genericInstantiation.push_back(getType(g));\r
+    }\r
+  }\r
   return result;\r
 }\r
 Variable getVariable(TocParser::VarContext * ctx)\r
@@ -77,11 +84,20 @@ Function getFunction(TocParser::FuncContext * ctx, std::shared_ptr<Context> pare
   Function result;\r
   result.name = ctx->funcName()->NAME()->toString();\r
   result.returnType = getType(ctx->type());\r
+  if (ctx->genericDecl() != nullptr)\r
+  {\r
+    for (auto t : ctx->genericDecl()->typeName())\r
+    {\r
+      result.genericTypeNames.push_back(t->getText());\r
+    }\r
+  }\r
+\r
   if (!ctx->parameter()->var().empty())\r
   {\r
     for (auto p : ctx->parameter()->var())\r
       result.parameters.push_back(getVariable(p));\r
   }\r
+\r
   if (ctx->body() != nullptr)\r
   {\r
     result.body = getBody(ctx->body(), parent);\r
@@ -97,6 +113,14 @@ Struct getStruct(TocParser::StructDeclContext * ctx, std::shared_ptr<Context> pa
 {\r
   Struct result;\r
   result.name = ctx->structName()->NAME()->toString();\r
+  if (ctx->genericDecl() != nullptr)\r
+  {\r
+    for (auto t : ctx->genericDecl()->typeName())\r
+    {\r
+      result.genericTypeNames.push_back(t->getText());\r
+    }\r
+  }\r
+\r
   for (auto m : ctx->structMember())\r
   {\r
     if (m->structVar() != nullptr)\r
@@ -199,6 +223,13 @@ Expr getExpr(TocParser::FuncExprContext * ctx)
   for (auto n : ctx->namespaceSpecifier())\r
     result._func.namespacePrefixes.push_back(n->typeName()->getText());\r
   result._func.functionName = ctx->funcName()->NAME()->toString();\r
+  if (ctx->genericInstantiation() != nullptr)\r
+  {\r
+    for (auto g : ctx->genericInstantiation()->type())\r
+    {\r
+      result._func.genericInstantiation.push_back(getType(g));\r
+    }\r
+  }\r
   for (auto e : ctx->expr())\r
     result._func.arguments.push_back(getExpr(e));\r
   return result;\r
@@ -209,6 +240,13 @@ Expr getExpr(TocParser::MethodExprContext * ctx)
   result.type = ExprType::Method;\r
   result._method.expr = std::make_unique<Expr>(getExpr(ctx->expr(0)));\r
   result._method.methodName = ctx->funcName()->NAME()->toString();\r
+  if (ctx->genericInstantiation() != nullptr)\r
+  {\r
+    for (auto g : ctx->genericInstantiation()->type())\r
+    {\r
+      result._method.genericInstantiation.push_back(getType(g));\r
+    }\r
+  }\r
   for (int i = 1; i < ctx->expr().size(); i++)\r
     result._method.arguments.push_back(getExpr(ctx->expr(i)));\r
   return result;\r
@@ -252,6 +290,7 @@ Expr getExpr(TocParser::DotExprContext * ctx)
   result.type = ExprType::Dot;\r
   result._dot.expr = std::make_unique<Expr>(getExpr(ctx->expr()));\r
   result._dot.identifier = ctx->varName()->getText();\r
+  result._dot.isPointer = ctx->arrow() != nullptr;\r
   return result;\r
 }\r
 Expr getExpr(TocParser::PrefixOpExprContext * ctx)\r