This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
why does dump_decl dump the scope of a FIELD_DECL?
- From: "Giovanni Bajo" <giovannibajo at libero dot it>
- To: "Gabriel Dos Reis" <gdr at integrable-solutions dot net>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Sat, 31 Jan 2004 21:41:52 +0100
- Subject: why does dump_decl dump the scope of a FIELD_DECL?
Hello Gaby,
dump_decl currently prints the scope of a FIELD_DECL, which makes it appear
like "int A::x" for things like:
struct A
{
int x;
};
It looks pretty goofy to me because if we dump the *field* name we probably
don't want the class name as well. For instance:
struct A
{
A();
int A;
};
error: field `int A::A' with same name as class
which is confusing. Is there a reason for this which I'm missing? Otherwise,
does something like this patch, which is sitting in my tree but currently
untested, makes sense to you?
Giovanni Bajo
Index: error.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/error.c,v
retrieving revision 1.241
diff -c -3 -p -r1.241 error.c
*** error.c 21 Dec 2003 21:07:30 -0000 1.241
--- error.c 31 Jan 2004 20:40:15 -0000
*************** dump_simple_decl (tree t, tree type, int
*** 739,745 ****
if (dump_type_prefix (type, flags) != none)
pp_space (cxx_pp);
}
! if (!DECL_INITIAL (t) || TREE_CODE (DECL_INITIAL (t)) !=
TEMPLATE_PARM_INDEX)
dump_scope (CP_DECL_CONTEXT (t), flags);
if (DECL_NAME (t))
dump_decl (DECL_NAME (t), flags);
--- 739,747 ----
if (dump_type_prefix (type, flags) != none)
pp_space (cxx_pp);
}
! if (flags & TFF_SCOPE
! && (!DECL_INITIAL (t)
! || TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX))
dump_scope (CP_DECL_CONTEXT (t), flags);
if (DECL_NAME (t))
dump_decl (DECL_NAME (t), flags);
*************** dump_decl (tree t, int flags)
*** 777,783 ****
pp_string (cxx_pp, "typedef ");
dump_simple_decl (t, DECL_ORIGINAL_TYPE (t)
? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t),
! flags);
break;
case VAR_DECL:
--- 779,785 ----
pp_string (cxx_pp, "typedef ");
dump_simple_decl (t, DECL_ORIGINAL_TYPE (t)
? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t),
! flags | TFF_SCOPE);
break;
case VAR_DECL:
*************** dump_decl (tree t, int flags)
*** 789,802 ****
break;
}
/* Else fall through. */
- case FIELD_DECL:
case PARM_DECL:
dump_simple_decl (t, TREE_TYPE (t), flags);
break;
case RESULT_DECL:
pp_string (cxx_pp, "<return value> ");
! dump_simple_decl (t, TREE_TYPE (t), flags);
break;
case NAMESPACE_DECL:
--- 791,807 ----
break;
}
/* Else fall through. */
case PARM_DECL:
+ dump_simple_decl (t, TREE_TYPE (t), flags | TFF_SCOPE);
+ break;
+
+ case FIELD_DECL:
dump_simple_decl (t, TREE_TYPE (t), flags);
break;
case RESULT_DECL:
pp_string (cxx_pp, "<return value> ");
! dump_simple_decl (t, TREE_TYPE (t), flags | TFF_SCOPE);
break;
case NAMESPACE_DECL:
*************** dump_decl (tree t, int flags)
*** 915,921 ****
if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
|| (DECL_INITIAL (t) &&
TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX))
! dump_simple_decl (t, TREE_TYPE (t), flags);
else if (DECL_NAME (t))
dump_decl (DECL_NAME (t), flags);
else if (DECL_INITIAL (t))
--- 920,926 ----
if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
|| (DECL_INITIAL (t) &&
TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX))
! dump_simple_decl (t, TREE_TYPE (t), flags | TFF_SCOPE);
else if (DECL_NAME (t))
dump_decl (DECL_NAME (t), flags);
else if (DECL_INITIAL (t))