* [patch 2/3] Extend C++ import to support renaming even declarations
@ 2010-04-30 18:16 Jan Kratochvil
2010-04-30 18:54 ` Tom Tromey
0 siblings, 1 reply; 5+ messages in thread
From: Jan Kratochvil @ 2010-04-30 18:16 UTC (permalink / raw)
To: gdb-patches; +Cc: Sami Wagiaalla
Hi,
the current C++ using-directive supports renaming of namespaces but it does
not support renaming of specific imported declarations. This is fine as C++
does not support the latter.
The Fortran patch 3/3 uses the existing FSF GDB C++ infrastructure, therefore
it had to extend it.
C++: using namespace A;
Fortran: use A
- namespace import, therefore not a "declaration" import
- no renaming happens
C++: using A::x;
Fortran: use A, only: x
- "declaration" import of the specific variable `x'.
- no renaming happens
namespace B = A;
Fortran has no way to address non-local namespace/module.
- namespace import, therefore not a "declaration" import
- renaming "A" to "B"
C++ cannot, it would be something like: using y = A::x;
Fortran: use A, only y => x
- "declaration" import of the specific variable `x'.
- renaming "x" to "y"
Therefore this patch implements the last case. It does not affect existing
C++ functionality in the other 3 cases.
No regressions on {x86_64,x86_64-m32,i686}-fedora12-linux-gnu for the whole
patch series.
Thanks,
Jan
2010-04-30 Jan Kratochvil <jan.kratochvil@redhat.com>
* cp-namespace.c (cp_lookup_symbol_imports): Support ALIAS for the
CURRENT->DECLARATION case.
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -355,12 +355,14 @@ cp_lookup_symbol_imports (const char *scope,
searched_cleanup = make_cleanup (reset_directive_searched, current);
/* If there is an import of a single declaration, compare the imported
- declaration with the sought out name. If there is a match pass
- current->import_src as NAMESPACE to direct the search towards the
- imported namespace. */
- if (current->declaration && strcmp (name, current->declaration) == 0)
+ declaration (after optional renaming by its alias) with the sought
+ out name. If there is a match pass current->import_src as NAMESPACE
+ to direct the search towards the imported namespace. */
+ if (current->declaration
+ && strcmp (name, current->alias ? current->alias
+ : current->declaration) == 0)
sym = cp_lookup_symbol_in_namespace (current->import_src,
- name,
+ current->declaration,
block,
domain);
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [patch 2/3] Extend C++ import to support renaming even declarations
2010-04-30 18:16 [patch 2/3] Extend C++ import to support renaming even declarations Jan Kratochvil
@ 2010-04-30 18:54 ` Tom Tromey
2010-04-30 21:34 ` Jan Kratochvil
0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2010-04-30 18:54 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches, Sami Wagiaalla
>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
Jan> Therefore this patch implements the last case. It does not affect existing
Jan> C++ functionality in the other 3 cases.
Jan> 2010-04-30 Jan Kratochvil <jan.kratochvil@redhat.com>
Jan> * cp-namespace.c (cp_lookup_symbol_imports): Support ALIAS for the
Jan> CURRENT-> DECLARATION case.
Please also update the documentation for struct using_direct to mention
this case. Right now the comment there indicates that alias==NULL in
all other cases.
This patch is ok with that change.
I wonder why the fields of using_direct are not const char *.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch 2/3] Extend C++ import to support renaming even declarations
2010-04-30 18:54 ` Tom Tromey
@ 2010-04-30 21:34 ` Jan Kratochvil
2010-05-03 18:02 ` Tom Tromey
0 siblings, 1 reply; 5+ messages in thread
From: Jan Kratochvil @ 2010-04-30 21:34 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches, Sami Wagiaalla
On Fri, 30 Apr 2010 20:54:12 +0200, Tom Tromey wrote:
> Please also update the documentation for struct using_direct to mention
> this case. Right now the comment there indicates that alias==NULL in
> all other cases.
OK this way?
(I understand the Fortran lines in the comment should be checked-in only with
the patch 3/3 implementing them.)
Thanks,
Jan
2010-04-30 Jan Kratochvil <jan.kratochvil@redhat.com>
* cp-namespace.c (cp_lookup_symbol_imports): Support ALIAS for the
CURRENT->DECLARATION case.
* cp-support.h (struct using_direct): Provide extended comment.
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -355,12 +355,14 @@ cp_lookup_symbol_imports (const char *scope,
searched_cleanup = make_cleanup (reset_directive_searched, current);
/* If there is an import of a single declaration, compare the imported
- declaration with the sought out name. If there is a match pass
- current->import_src as NAMESPACE to direct the search towards the
- imported namespace. */
- if (current->declaration && strcmp (name, current->declaration) == 0)
+ declaration (after optional renaming by its alias) with the sought
+ out name. If there is a match pass current->import_src as NAMESPACE
+ to direct the search towards the imported namespace. */
+ if (current->declaration
+ && strcmp (name, current->alias ? current->alias
+ : current->declaration) == 0)
sym = cp_lookup_symbol_in_namespace (current->import_src,
- name,
+ current->declaration,
block,
domain);
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -37,19 +37,44 @@ struct type;
struct demangle_component;
/* This struct is designed to store data from using directives. It
- says that names from namespace IMPORT_SRC should be visible within
- namespace IMPORT_DEST. These form a linked list; NEXT is the next element
- of the list. If the imported namespace has been aliased, ALIAS is set to a
- string representing the alias. Otherwise, ALIAS is NULL.
- Eg:
- namespace C = A::B;
- ALIAS = "C"
- DECLARATION is the name of the imported declaration, if this import
- statement represents one.
- Eg:
- using A::x;
- Where x is variable in namespace A. DECLARATION is set to x.
-*/
+ says that names from namespace IMPORT_SRC should be visible within namespace
+ IMPORT_DEST. These form a linked list; NEXT is the next element of the
+ list. If the imported namespace or declaration has been aliased within the
+ IMPORT_DEST namespace, ALIAS is set to a string representing the alias.
+ Otherwise, ALIAS is NULL. DECLARATION is the name of the imported
+ declaration, if this import statement represents one. Otherwise DECLARATION
+ is NULL and this import statement represents a namespace.
+
+ C++: using namespace A;
+ Fortran: use A
+ import_src = "A"
+ import_dest = local scope of the import statement even such as ""
+ alias = NULL
+ declaration = NULL
+
+ C++: using A::x;
+ Fortran: use A, only: x
+ import_src = "A"
+ import_dest = local scope of the import statement even such as ""
+ alias = NULL
+ declaration = "x"
+ The declaration will get imported as import_dest::x.
+
+ C++: namespace LOCALNS = A;
+ Fortran has no way to address non-local namespace/module.
+ import_src = "A"
+ import_dest = local scope of the import statement even such as ""
+ alias = "LOCALNS"
+ declaration = NULL
+ The namespace will get imported as the import_dest::LOCALNS namespace.
+
+ C++ cannot express it, it would be something like: using localname = A::x;
+ Fortran: use A, only localname => x
+ import_src = "A"
+ import_dest = local scope of the import statement even such as ""
+ alias = "localname"
+ declaration = "x"
+ The declaration will get imported as localname or `import_dest`localname. */
struct using_direct
{
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-05-03 20:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-30 18:16 [patch 2/3] Extend C++ import to support renaming even declarations Jan Kratochvil
2010-04-30 18:54 ` Tom Tromey
2010-04-30 21:34 ` Jan Kratochvil
2010-05-03 18:02 ` Tom Tromey
2010-05-03 20:11 ` Jan Kratochvil
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox