This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PCH] Handle VLAs (as in struct tree_vec)
- From: Geoffrey Keating <geoffk at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 4 Apr 2002 10:48:08 -0800
- Subject: [PCH] Handle VLAs (as in struct tree_vec)
This adds a little more power to gengtype.
Bootstrapped & tested on i686-pc-linux-gnu.
--
Geoff Keating <geoffk@redhat.com>
===File ~/patches/pchbranch-vla.patch=======================
2002-04-02 Geoffrey Keating <geoffk@redhat.com>
* gengtype.c (write_gc_structure_fields): Handle variable-length
TYPE_ARRAYs.
Index: gengtype.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/gengtype.c,v
retrieving revision 1.1.2.5
diff -p -u -p -r1.1.2.5 gengtype.c
--- gengtype.c 2002/03/13 18:32:01 1.1.2.5
+++ gengtype.c 2002/04/04 18:44:38
@@ -661,8 +661,9 @@ write_gc_structure_fields (of, s, val, p
type_p t;
int i;
- if (strcmp (f->type->u.a.len, "0") == 0
- || strcmp (f->type->u.a.len, "1") == 0)
+ if (! length &&
+ (strcmp (f->type->u.a.len, "0") == 0
+ || strcmp (f->type->u.a.len, "1") == 0))
error_at_line (&f->line,
"field `%s' is array of size %s",
f->name, f->type->u.a.len);
@@ -673,10 +674,22 @@ write_gc_structure_fields (of, s, val, p
fprintf (of, "%*ssize_t i%d_%d;\n", indent, "", loopcounter, i);
for (t = f->type, i=0; t->kind == TYPE_ARRAY; t = t->u.a.p, i++)
{
+ const char *p;
+
fprintf (of,
- "%*sfor (i%d_%d = 0; i%d_%d < (%s); i%d_%d++) {\n",
- indent, "", loopcounter, i, loopcounter, i,
- t->u.a.len, loopcounter, i);
+ "%*sfor (i%d_%d = 0; i%d_%d < (",
+ indent, "", loopcounter, i, loopcounter, i);
+ if (i == 0 && length != NULL)
+ {
+ for (p = length; *p; p++)
+ if (*p != '%')
+ fputc (*p, of);
+ else
+ fprintf (of, "(%s)", val);
+ }
+ else
+ fputs (t->u.a.len, of);
+ fprintf (of, "); i%d_%d++) {\n", loopcounter, i);
indent += 2;
}
============================================================