On 05/07/2013 04:41 AM, Richard Biener wrote:
Eh, two NULL_TREE terminators are ugly ... callers know the number of elements,
so maybe instead pass that number as argument?

OK, sure.

Can we overload build_constructor with a variadic variant?  Thus,

tree build_constructor (tree type, vec<constructor_elt, va_gc> *vals);
tree build_constructor (tree type, unsigned n, ...);

Unfortunately, no; with that overload set,

 build_constructor (type, NULL)

is ambiguous.

Here's what I'm applying:

commit ba2a6ab026009ee8368f8d381263ce2a5a527142
Author: Jason Merrill <ja...@redhat.com>
Date:   Mon May 6 23:15:08 2013 -0400

    	* tree.c (build_constructor_va): New.
    	* tree.h: Declare it.

diff --git a/gcc/tree.c b/gcc/tree.c
index 444c876..55fa99b 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -1467,6 +1467,27 @@ build_constructor_from_list (tree type, tree vals)
   return build_constructor (type, v);
 }
 
+/* Return a new CONSTRUCTOR node whose type is TYPE.  NELTS is the number
+   of elements, provided as index/value pairs.  */
+
+tree
+build_constructor_va (tree type, int nelts, ...)
+{
+  vec<constructor_elt, va_gc> *v = NULL;
+  va_list p;
+
+  va_start (p, nelts);
+  vec_alloc (v, nelts);
+  while (nelts--)
+    {
+      tree index = va_arg (p, tree);
+      tree value = va_arg (p, tree);
+      CONSTRUCTOR_APPEND_ELT (v, index, value);
+    }
+  va_end (p);
+  return build_constructor (type, v);
+}
+
 /* Return a new FIXED_CST node whose type is TYPE and value is F.  */
 
 tree
diff --git a/gcc/tree.h b/gcc/tree.h
index 2b6f13b..cd1d7613 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4763,6 +4763,7 @@ extern tree build_vector_from_val (tree, tree);
 extern tree build_constructor (tree, vec<constructor_elt, va_gc> *);
 extern tree build_constructor_single (tree, tree, tree);
 extern tree build_constructor_from_list (tree, tree);
+extern tree build_constructor_va (tree, int, ...);
 extern tree build_real_from_int_cst (tree, const_tree);
 extern tree build_complex (tree, tree, tree);
 extern tree build_one_cst (tree);

Reply via email to