From 535335bffc08ebcfbabfd8f1bbff2fa6d5f0e429 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 14 Jul 2010 13:01:03 -0400 Subject: init.c (sort_mem_initializers): Rename "field_type" to "ctx". * init.c (sort_mem_initializers): Rename "field_type" to "ctx". (build_field_list): Cache field type. From-SVN: r162188 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/init.c | 42 ++++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 05a4dfa..ea3e9b5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2010-07-14 Jason Merrill + * init.c (sort_mem_initializers): Rename "field_type" to "ctx". + (build_field_list): Cache field type. + Implement C++0x unrestricted unions (N2544) * class.c (check_field_decl): Loosen union handling in C++0x. * method.c (walk_field_subobs): Split out from... diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 4e7cab3..98a45cd 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -564,25 +564,27 @@ build_field_list (tree t, tree list, int *uses_unions_p) for (fields = TYPE_FIELDS (t); fields; fields = TREE_CHAIN (fields)) { + tree fieldtype; + /* Skip CONST_DECLs for enumeration constants and so forth. */ if (TREE_CODE (fields) != FIELD_DECL || DECL_ARTIFICIAL (fields)) continue; + fieldtype = TREE_TYPE (fields); /* Keep track of whether or not any fields are unions. */ - if (TREE_CODE (TREE_TYPE (fields)) == UNION_TYPE) + if (TREE_CODE (fieldtype) == UNION_TYPE) *uses_unions_p = 1; /* For an anonymous struct or union, we must recursively consider the fields of the anonymous type. They can be directly initialized from the constructor. */ - if (ANON_AGGR_TYPE_P (TREE_TYPE (fields))) + if (ANON_AGGR_TYPE_P (fieldtype)) { /* Add this field itself. Synthesized copy constructors initialize the entire aggregate. */ list = tree_cons (fields, NULL_TREE, list); /* And now add the fields in the anonymous aggregate. */ - list = build_field_list (TREE_TYPE (fields), list, - uses_unions_p); + list = build_field_list (fieldtype, list, uses_unions_p); } /* Add this field. */ else if (DECL_NAME (fields)) @@ -718,7 +720,7 @@ sort_mem_initializers (tree t, tree mem_inits) for (p = &sorted_inits; *p; ) { tree field; - tree field_type; + tree ctx; int done; init = *p; @@ -736,13 +738,13 @@ sort_mem_initializers (tree t, tree mem_inits) /* See if this field is a member of a union, or a member of a structure contained in a union, etc. */ - for (field_type = DECL_CONTEXT (field); - !same_type_p (field_type, t); - field_type = TYPE_CONTEXT (field_type)) - if (TREE_CODE (field_type) == UNION_TYPE) + for (ctx = DECL_CONTEXT (field); + !same_type_p (ctx, t); + ctx = TYPE_CONTEXT (ctx)) + if (TREE_CODE (ctx) == UNION_TYPE) break; /* If this field is not a member of a union, skip it. */ - if (TREE_CODE (field_type) != UNION_TYPE) + if (TREE_CODE (ctx) != UNION_TYPE) goto next; /* If this union member has no explicit initializer, splice @@ -766,37 +768,37 @@ sort_mem_initializers (tree t, tree mem_inits) union { struct { int i; int j; }; }; initializing both `i' and `j' makes sense. */ - field_type = DECL_CONTEXT (field); + ctx = DECL_CONTEXT (field); done = 0; do { - tree last_field_type; + tree last_ctx; - last_field_type = DECL_CONTEXT (last_field); + last_ctx = DECL_CONTEXT (last_field); while (1) { - if (same_type_p (last_field_type, field_type)) + if (same_type_p (last_ctx, ctx)) { - if (TREE_CODE (field_type) == UNION_TYPE) + if (TREE_CODE (ctx) == UNION_TYPE) error_at (DECL_SOURCE_LOCATION (current_function_decl), "initializations for multiple members of %qT", - last_field_type); + last_ctx); done = 1; break; } - if (same_type_p (last_field_type, t)) + if (same_type_p (last_ctx, t)) break; - last_field_type = TYPE_CONTEXT (last_field_type); + last_ctx = TYPE_CONTEXT (last_ctx); } /* If we've reached the outermost class, then we're done. */ - if (same_type_p (field_type, t)) + if (same_type_p (ctx, t)) break; - field_type = TYPE_CONTEXT (field_type); + ctx = TYPE_CONTEXT (ctx); } while (!done); -- cgit v1.1