This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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: [PATCH] [RFC] PR c++/16874: make it easier to use anonymous namespaces


Patrick Palka writes:
 > Symbols referring to names defined inside a top-level C++ anonymous
 > namespace have an "(anonymous namespace)::" prefix attached to them.
 > Referring to such symbols in commands such as "print" and "break" is
 > cumbersome because the prefix is tricky to type and symbols with this
 > prefix do not TAB-complete properly.
 > 
 > To make it easier to refer to such symbols, this patch allows the user
 > to omit "(anonymous namespace)::" prefix from these symbols.  In other
 > words, this patch allows the symbol "(anonymous namespace)::FOO" to be
 > referred to as "FOO".  Likewise  "(anonymous namespace)::FOO::BAR" ==>
 > "FOO::BAR".  But not "FOO::(anonymous namespace)::BAZ" ==> "FOO::BAZ"
 > because the anonymous namespace in question is not the top-level one.
 > It also doesn't handle "(anonymous namespace)::(anonymous namespace)::FOO"
 > ==> "FOO".
 > 
 > This patch is implemented in three hunks.  The cp-namespace.c hunk
 > handles the elision of the anon prefix during symbol lookup in the
 > expression context (.e.g. "print foo").  The linespec.c hunk handles the
 > elision of the anon prefix during symbol lookup in the breakpoint
 > context (e.g. "break foo").  And finally the symtab.c hunk handles the
 > elision of the anon prefix during symbol completion.  This patch does
 > not yet have a test case, but nonetheless I would very much appreciate
 > comments on the approach that this patch takes in address the mentioned
 > PR.
 > 
 > I chose this approach because symbols defined in the root anonymous
 > namespace are very akin to static symbols so it is intuitive and
 > convenient to treat them as such, that is, to pretend that their
 > (anonymous namespace):: prefix doesn't even exist (unless the prefix was
 > explicitly given by the user).
 > 
 > gdb/ChangeLog:
 > 
 > 	* cp-support.h (cp_in_root_anonymous_namespace_p): New function.
 > 	* cp-namespace.c (cp_lookup_symbol_nonlocal): Try looking for
 > 	the symbol within the root anonymous namespace.
 > 	* linespec.c (find_linespec_symbols): Likewise.
 > 	* symtab.c (completion_list_add_name): Ignore the root anonymous
 > 	namespace prefix when looking for matching symbols.

Cool.

I need to look this over but can't in the next few days.
On the off chance that someone else looks it over and
gives it an OK, please hold off committing this until
I can review it too.

Thanks!


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