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]

Namespace level TYPE_DECLs for typedefs


Hello,

I'm not sure if this is the right list for this question.  If not, would
someone please direct me to the correct list?  Thanks.

I've been studying the internal representation off GCC and the C++
front-end, and have noticed an inconsistency in the tree structure.  I've
been encountering this problem for a while, and it still exists in a CVS
update I did this morning (Jan 30) from the main development tree.

Consider the following program:

--------- example.cxx ----------
namespace N
{
  typedef int Int;
  typedef float Float;
}
--------------------------------

I run

g++ -fdump-translation-unit-example.dump -fsyntax-only example.cxx

A portion of the output is given below, and the whole thing is attached.
Studying this, we see that the TYPE_DECL nodes for the Int and Float
typedefs exist in the cp_namespace_decls of the global namespace, not of
namespace "N".  The cp_namespace_decls chain of namespace "N" is empty.

I've put in some tree-walking code at the end of finish_translation_unit
in cp/semantics.c to print out some information, and the CP_DECL_CONTEXT
of the TYPE_DECL nodes also point back to the global namespace.

If we change the example's code to

struct N
{
  typedef int Int;
  typedef float Float;
};

then the representation stores what we would expect, with the typedefs'
TYPE_DECL nodes inside the chain of declarations within struct "N".

In either case, the compiler still handles the names correctly (N::Int can
be referenced from the global namespace, but just plain Int cannot).  
I've been tracing the name lookup code for days, but cannot find an
explanation.  Any help would be appreciated.

Thanks,
-Brad

-------------- example.dump ------------------
@1      namespace_decl   name: @2      srcp: <internal>:0      
                         dcls: @3      
@2      identifier_node  strg: ::      lngt: 2       
@3      type_decl        name: @4      type: @5      srcp: test4.cxx:4      
                         chan: @6      
@4      identifier_node  strg: Float   lngt: 5       
@5      real_type        name: @3      unql: @7      size: @8      
                         algn: 32      prec: 32      
@6      type_decl        name: @9      type: @10     srcp: test4.cxx:3      
                         chan: @11     
@7      real_type        name: @12     size: @8      algn: 32      
                         prec: 32      
@8      integer_cst      type: @13     low : 32      
@9      identifier_node  strg: Int     lngt: 3       
@10     integer_type     name: @6      unql: @14     size: @15     
                         algn: 32      prec: 32      min : @16     
                         max : @17     
@11     namespace_decl   name: @18     type: @19     srcp: test4.cxx:2      
                         chan: @20     
@12     type_decl        name: @21     type: @7      srcp: <internal>:0      
                         chan: @22     
@13     integer_type     name: @23     size: @24     algn: 64      
                         prec: 36      unsigned      min : @25     
                         max : @26     
@14     integer_type     name: @27     size: @15     algn: 32      
                         prec: 32      min : @16     max : @17     
@15     integer_cst      type: @13     low : 32      
@16     integer_cst      type: @14     high: -1      low : -2147483648 
@17     integer_cst      type: @14     low : 2147483647 
@18     identifier_node  strg: N       lngt: 1       
@19     void_type        name: @28     algn: 8       
@20     var_decl         name: @29     type: @30     srcp: <internal>:0      
                         artificial    chan: @31     init: @32     
                         size: @33     algn: 8       used: 0       
@21     identifier_node  strg: float   lngt: 5       
@22     type_decl        type: @34     srcp: <internal>:0      
                         chan: @35     
@23     identifier_node  strg: bit_size_type         lngt: 13      
@24     integer_cst      type: @13     low : 64      
@25     integer_cst      type: @13     low : 0       
@26     integer_cst      type: @13     high: 15      low : -1      
@27     type_decl        name: @36     type: @14     srcp: <internal>:0      
                         chan: @37     
@28     type_decl        name: @38     type: @19     srcp: <internal>:0      
                         chan: @39     
@29     identifier_node  strg: __PRETTY_FUNCTION__   lngt: 19      
@30     array_type       qual: c       unql: @40     size: @33     
                         algn: 8       elts: @41     domn: @42     
@31     var_decl         name: @43     type: @44     srcp: <internal>:0      
                         artificial    chan: @45     init: @46     
                         size: @47     algn: 8       used: 0       
@32     string_cst       type: @30     strg: top level lngt: 10      
@33     integer_cst      type: @13     low : 80      
@34     integer_type     size: @48     algn: 64      prec: 64      
                         unsigned      min : @49     max : @50     
@35     type_decl        type: @51     srcp: <internal>:0      
                         chan: @52     
@36     identifier_node  strg: int     lngt: 3       
@37     namespace_decl   name: @53     srcp: <internal>:0      
                         C             dcls: @54     
@38     identifier_node  strg: void    lngt: 4       
@39     type_decl        name: @55     type: @56     srcp: <internal>:0      
                         chan: @57     
@40     array_type       size: @33     algn: 8       elts: @58     
                         domn: @42     
@41     integer_type     qual: c       name: @59     unql: @58     
                         size: @47     algn: 8       prec: 8       
                         min : @60     max : @61     
@42     integer_type     size: @15     algn: 32      prec: 32      
                         min : @62     max : @63     
...............


example.dump.gz


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