ref: 710daae0fea4176e4524f1107c46058cb8f197a7
parent: f3b75c3f5712d0be6e769da93e97fb0c1ae77143
author: Ori Bernstein <[email protected]>
date: Sat Jan 14 16:50:16 EST 2012
Generify nlappend. *sigh*. I want generics, so I don't have to do that crap.
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -158,10 +158,10 @@
toplev
: decl
- {nlappend(&file->file.stmts, &file->file.nstmts, $1);
+ {lappend(&file->file.stmts, &file->file.nstmts, $1);
putdcl(file->file.globls, $1->decl.sym);}
| use
- {nlappend(&file->file.uses, &file->file.nuses, $1);}
+ {lappend(&file->file.uses, &file->file.nuses, $1);}
| package
| tydef
{die("tydef unimplemented");}
@@ -263,9 +263,9 @@
argdefs : declcore
{$$.line = $1->line;
$$.nl = NULL;
- $$.nn = 0; nlappend(&$$.nl, &$$.nn, $1);}
+ $$.nn = 0; lappend(&$$.nl, &$$.nn, $1);}
| argdefs TComma declcore
- {nlappend(&$$.nl, &$$.nn, $3);}
+ {lappend(&$$.nl, &$$.nn, $3);}
;
structdef
@@ -275,9 +275,9 @@
structbody
: structelt
- {$$.nl = NULL; $$.nn = 0; nlappend(&$$.nl, &$$.nn, $1);}
+ {$$.nl = NULL; $$.nn = 0; lappend(&$$.nl, &$$.nn, $1);}
| structbody structelt
- {if ($2) {nlappend(&$$.nl, &$$.nn, $2);}}
+ {if ($2) {lappend(&$$.nl, &$$.nn, $2);}}
;
structelt
@@ -296,9 +296,9 @@
unionbody
: unionelt
- {$$.nl = NULL; $$.nn = 0; nlappend(&$$.nl, &$$.nn, $1);}
+ {$$.nl = NULL; $$.nn = 0; lappend(&$$.nl, &$$.nn, $1);}
| unionbody unionelt
- {if ($2) {nlappend(&$$.nl, &$$.nn, $2);}}
+ {if ($2) {lappend(&$$.nl, &$$.nn, $2);}}
;
unionelt
@@ -315,9 +315,9 @@
;
enumbody: enumelt
- {$$.nl = NULL; $$.nn = 0; if ($1) nlappend(&$$.nl, &$$.nn, $1);}
+ {$$.nl = NULL; $$.nn = 0; if ($1) lappend(&$$.nl, &$$.nn, $1);}
| enumbody enumelt
- {if ($2) {nlappend(&$$.nl, &$$.nn, $2);}}
+ {if ($2) {lappend(&$$.nl, &$$.nn, $2);}}
;
enumelt : TIdent TEndln
@@ -436,9 +436,9 @@
;
arglist : asnexpr
- {$$.nl = NULL; $$.nn = 0; nlappend(&$$.nl, &$$.nn, $1);}
+ {$$.nl = NULL; $$.nn = 0; lappend(&$$.nl, &$$.nn, $1);}
| arglist TComma asnexpr
- {nlappend(&$$.nl, &$$.nn, $3);}
+ {lappend(&$$.nl, &$$.nn, $3);}
| /* empty */
{$$.nl = NULL; $$.nn = 0;}
;
@@ -469,9 +469,9 @@
;
params : declcore
- {$$.nl = NULL; $$.nn = 0; nlappend(&$$.nl, &$$.nn, $1);}
+ {$$.nl = NULL; $$.nn = 0; lappend(&$$.nl, &$$.nn, $1);}
| params TComma declcore
- {nlappend(&$$.nl, &$$.nn, $3);}
+ {lappend(&$$.nl, &$$.nn, $3);}
| /* empty */
{$$.nl = NULL; $$.nn = 0;}
;
@@ -528,10 +528,10 @@
: stmt
{$$ = mkblock(line, mkstab());
if ($1)
- nlappend(&$$->block.stmts, &$$->block.nstmts, $1);}
+ lappend(&$$->block.stmts, &$$->block.nstmts, $1);}
| blockbody stmt
{if ($2)
- nlappend(&$$->block.stmts, &$$->block.nstmts, $2);}
+ lappend(&$$->block.stmts, &$$->block.nstmts, $2);}
;
label : TColon TIdent
--- a/parse/node.c
+++ b/parse/node.c
@@ -52,7 +52,7 @@
n->expr.op = op;
va_start(ap, op);
while ((arg = va_arg(ap, Node*)) != NULL)
- nlappend(&n->expr.args, &n->expr.nargs, arg);
+ lappend(&n->expr.args, &n->expr.nargs, arg);
va_end(ap);
return n;
@@ -65,7 +65,7 @@
n = mkexpr(line, Ocall, fn, NULL);
for (i = 0; i < nargs; i++)
- nlappend(&n->expr.args, &n->expr.nargs, args[i]);
+ lappend(&n->expr.args, &n->expr.nargs, args[i]);
return n;
}
@@ -227,12 +227,14 @@
return n;
}
-void nlappend(Node ***nl, size_t *len, Node *n)
+void lappend(void *l, size_t *len, void *n)
{
- assert(n != NULL);
+ void ***pl;
- *nl = xrealloc(*nl, (*len + 1)*sizeof(Node*));
- (*nl)[*len] = n;
+ assert(n != NULL);
+ pl = l;
+ *pl = xrealloc(*pl, (*len + 1)*sizeof(Node*));
+ (*pl)[*len] = n;
(*len)++;
}
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -341,7 +341,7 @@
Node *unpickle(FILE *fd);
/* convenience func */
-void nlappend(Node ***nl, size_t *len, Node *n);
+void lappend(void *nl, size_t *len, void *n); /* ugly hack; nl is void* because void*** != @a*** */
/* backend functions */
void gen(void);