]> gitweb.ps.run Git - toc/blobdiff - src/generic.h
comments
[toc] / src / generic.h
index df203b327305c556a786dc274343061448c5cdf2..33323e4eb8e560289faac453b23934b8a5340565 100644 (file)
@@ -4,6 +4,7 @@
 #include "typeInfo.h"\r
 #include "visit.h"\r
 \r
 #include "typeInfo.h"\r
 #include "visit.h"\r
 \r
+// add a generic instantiation if its not in the vector already\r
 void addGenericInstantiation(\r
   std::vector<std::vector<Type>> & insts,\r
   const std::vector<Type> & newInst)\r
 void addGenericInstantiation(\r
   std::vector<std::vector<Type>> & insts,\r
   const std::vector<Type> & newInst)\r
@@ -32,6 +33,8 @@ Program instantiateGenerics(const Program & p)
 \r
   // Find generic instantiations\r
 \r
 \r
   // Find generic instantiations\r
 \r
+  // visit expressions (only function calls are considered) and types,\r
+  // find the function/struct by pointer and add an instantiation\r
   Visitor findGenericInstantiations;\r
   findGenericInstantiations.onExpr =\r
   [&](const Expr & e, const std::shared_ptr<Context> ctx)\r
   Visitor findGenericInstantiations;\r
   findGenericInstantiations.onExpr =\r
   [&](const Expr & e, const std::shared_ptr<Context> ctx)\r
@@ -48,7 +51,6 @@ Program instantiateGenerics(const Program & p)
         addGenericInstantiation(std::get<0>(*f)->genericInstantiations, e._func.genericInstantiation);\r
       }\r
     }\r
         addGenericInstantiation(std::get<0>(*f)->genericInstantiations, e._func.genericInstantiation);\r
       }\r
     }\r
-    // TODO: generic methods\r
   };\r
   findGenericInstantiations.onType =\r
   [&](const Type & t, const std::shared_ptr<Context> ctx)\r
   };\r
   findGenericInstantiations.onType =\r
   [&](const Type & t, const std::shared_ptr<Context> ctx)\r
@@ -72,6 +74,10 @@ Program instantiateGenerics(const Program & p)
   return result;\r
 }\r
 \r
   return result;\r
 }\r
 \r
+// generate the appendix for C struct/function names\r
+// including array/pointer indicators because\r
+// there might be distinct instantiations\r
+// for int and int* for example\r
 std::string genericAppendix(const std::vector<Type> & ts)\r
 {\r
   std::stringstream sstr;\r
 std::string genericAppendix(const std::vector<Type> & ts)\r
 {\r
   std::stringstream sstr;\r