This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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))



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]