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]

Re: RFD - cleaning up C identifier lookup


Zack Weinberg <zack at codesourcery dot com> writes:

[...]

| Second, the distinction between global_value and local_value is
| artificial.  I propose to remove it and use the existing mechanism for
| block-scope shadows to handle shadowing of globals.  That would free
| up another slot, but instead of removing it altogether I plan to
| recycle it for the type-tag namespace:
| 
| struct lang_identifier GTY(())
| {
|   struct c_common_identifier common_id;
|   tree symbol_value;
|   tree tag_value;
|   tree label_value;
| }
| 
| That allows elimination of the disgusting linear-or-worse search
| algorithm used by lookup_tag, and I hope it will allow removal of
| lookup_tag_reverse entirely.
| 
| Much of this stuff could also be applied to the C++ front end also,

That might; but in fact, that would be a complication (and hardly an
improvement over current situation) for C++. 

A distinction is that C++ has a single name space  as opposed to C.
An immediate consequence is that the C++ front-end would have to jump
through whoops to ensure that we can C++ semantics right.

Second,  scope rules in C++ are different from C's.  E.g., in C, the
follwoing 

   struct A {
     int i;
      struct B {
        int j;
      };
   };
   
declares both A and B in the global namespace, whereas in C++, it
defined only A in the global namespace and B in the class-scope of A.

The route I take on this issue for C++ is to get rid of the confusion
notions of binding-level and scope in G++.  Instead, I just use the
standard notion of scope and implement essentially 

  1) local scopes (these are blocks) with the refinements:
       + try-scope
       + catch-scope
       + for-while scope

  2) function prototype scopes
 
  3) class scope
  
  4) namespace scope

  5) template prototype scope

I use a hash-table to implement name lookup for 4) and 5).  I keep the
existing linear list for 2) and 5).  I was glad to see Mark already
made part of that route with the new parser in 3.4.  There is no
reason name lookup in C++ front-end should be as monstrous as in 3.3.

In this scheme, I replaced the currenr g++'s

    struct lang_identifier GTY(())
    {
      struct c_common_identifier c_common;
      cxx_binding *namespace_bindings;
      cxx_binding *bindings;
      tree class_value;
      tree class_template_info;
      struct lang_id2 *x;
    };

with

    struct lang_identifier GTY(())
    {
      struct c_common_identifier c_common;
      tree class_template_info;
      struct lang_id2 *x;
    };

There are opportunities to do further reductions.
 
-- Gaby


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