shithub: mc

Download patch

ref: 1ef5877bce5a4fcbe6e68b00f1ba087384d6343c
parent: 89c2d615ca55d511bd394607534091b78cfe82b4
author: Ori Bernstein <[email protected]>
date: Wed Aug 21 06:23:29 EDT 2013

Unify the creation of tyname and tygeneric.

--- a/parse/gram.y
+++ b/parse/gram.y
@@ -269,12 +269,13 @@
 
 tydef   : Ttype typeid Tasn type
             {$$ = $2;
-             if ($2.params)
-                 $$.type = mktygeneric($2.line, mkname($2.line, $2.name), $2.params, $2.nparams, $4);
-             else
-                 $$.type = mktyname($2.line, mkname($2.line, $2.name), $4);}
+             $$.type = mktyname($2.line, mkname($2.line, $2.name), $2.params, $2.nparams, $4);
+	     if ($2.params)
+		$$.type->isgeneric = 1;}
         | Ttype typeid
-            {$$ = $2;}
+            {$$ = $2;
+	     if ($2.params)
+		$$.type->isgeneric = 1;}
         ;
 
 typeid  : Tident
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -353,8 +353,7 @@
 Type *tydup(Type *t); /* shallow duplicate; all subtypes/members/... kept */
 Type *mktyvar(int line);
 Type *mktyparam(int line, char *name);
-Type *mktyname(int line, Node *name, Type *base);
-Type *mktygeneric(int line, Node *name, Type **params, size_t nparams, Type *base);
+Type *mktyname(int line, Node *name, Type **params, size_t nparams, Type *base);
 Type *mktyunres(int line, Node *name, Type **params, size_t nparams);
 Type *mktyarray(int line, Type *base, Node *sz);
 Type *mktyslice(int line, Type *base);
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -59,7 +59,7 @@
 		for (i = 0; i < t->nparam; i++)
 		    if (!hthas(tsmap, t->param[i]))
 			htput(tsmap, t->param[i], mktyvar(t->param[i]->line));
-		ret = mktyname(t->line, t->name, tyspecialize(t->sub[0], tsmap));
+		ret = mktyname(t->line, t->name, NULL, 0, tyspecialize(t->sub[0], tsmap));
 		htput(tsmap, t, ret);
 		for (i = 0; i < t->nparam; i++)
 		    lappend(&ret->param, &ret->nparam, tyspecialize(t->param[i], tsmap));
--- a/parse/type.c
+++ b/parse/type.c
@@ -146,21 +146,10 @@
     return t;
 }
 
-Type *mktygeneric(int line, Node *name, Type **param, size_t nparam, Type *base)
+Type *mktyname(int line, Node *name, Type **param, size_t nparam, Type *base)
 {
     Type *t;
 
-    t = mktyname(line, name, base);
-    t->param = param;
-    t->nparam = nparam;
-    t->isgeneric = 1;
-    return t;
-}
-
-Type *mktyname(int line, Node *name, Type *base)
-{
-    Type *t;
-
     t = mktype(line, Tyname);
     t->name = name;
     t->nsub = 1;
@@ -167,6 +156,8 @@
     t->cstrs = bsdup(base->cstrs);
     t->sub = xalloc(sizeof(Type*));
     t->sub[0] = base;
+    t->param = param;
+    t->nparam = nparam;
     return t;
 }