+2010-03-15 Sami Wagiaalla <swagiaal@redhat.com>
+
+ PR c++/7936:
+ * cp-support.h: Added char *declaration element to using_direct
+ data struct.
+ (cp_add_using): Added char *declaration argument.
+ (cp_add_using_directive): Ditto.
+ (cp_lookup_symbol_imports): made extern.
+ * cp-namespace.c: Updated with the above changes.
+ * dwarf2read.c (read_import_statement): Ditto.
+ (read_namespace): Ditto.
+ (read_import_statement): Support import declarations.
+ * cp-namespace.c (cp_lookup_symbol_imports): Check for imported
+ declarations.
+ Added support for 'declaration_only' search.
+ (cp_lookup_symbol_namespace): Attempt to search for the name as
+ is before consideration of imports.
+ * symtab.c (lookup_symbol_aux_local): Added a 'declaration_only'
+ search at every block level search.
+ Now takes language argument.
+ (lookup_symbol_aux): Updated.
+
2010-03-15 Tom Tromey <tromey@redhat.com>
* c-exp.y (name_not_typename): Add 'operator' clause.
anonymous namespace. So add symbols in it to the
namespace given by the previous component if there is
one, or to the global namespace if there isn't. */
- cp_add_using_directive (dest, src, NULL,
+ cp_add_using_directive (dest, src, NULL, NULL,
&SYMBOL_SYMTAB (symbol)->objfile->objfile_obstack);
}
/* The "+ 2" is for the "::". */
Create a new struct using_direct which imports the namespace SRC into the
scope DEST. ALIAS is the name of the imported namespace in the current
scope. If ALIAS is NULL then the namespace is known by its original name.
- The arguments are copied into newly allocated memory so they can be
- temporaries. */
+ DECLARATION is the name if the imported varable if this is a declaration
+ import (Eg. using A::x), otherwise it is NULL. The arguments are copied
+ into newly allocated memory so they can be temporaries. */
void
-cp_add_using_directive (const char *dest, const char *src, const char *alias,
+cp_add_using_directive (const char *dest,
+ const char *src,
+ const char *alias,
+ const char *declaration,
struct obstack *obstack)
{
struct using_direct *current;
struct using_direct *new;
-
+
/* Has it already been added? */
for (current = using_directives; current != NULL; current = current->next)
&& strcmp (current->import_dest, dest) == 0
&& ((alias == NULL && current->alias == NULL)
|| (alias != NULL && current->alias != NULL
- && strcmp (alias, current->alias) == 0)))
+ && strcmp (alias, current->alias) == 0))
+ && ((declaration == NULL && current->declaration == NULL)
+ || (declaration != NULL && current->declaration != NULL
+ && strcmp (declaration, current->declaration) == 0)))
return;
}
if (alias != NULL)
new->alias = obsavestring (alias, strlen (alias), obstack);
+ if (declaration != NULL)
+ new->declaration = obsavestring (declaration, strlen (declaration),
+ obstack);
+
new->next = using_directives;
using_directives = new;
}
if (sym != NULL)
return sym;
- return cp_lookup_symbol_namespace (scope, name, block, domain, 1);
+ return cp_lookup_symbol_namespace (scope, name, block, domain);
}
-/* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in
+/* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in
cp_lookup_symbol_nonlocal. */
static struct symbol *
}
/* Search for NAME by applying all import statements belonging
- to BLOCK which are applicable in SCOPE.
+ to BLOCK which are applicable in SCOPE. If DECLARATION_ONLY the search
+ is restricted to using declarations.
+ Example:
+
+ namespace A{
+ int x;
+ }
+ using A::x;
+
If SEARCH_PARENTS the search will include imports which are applicable in
parents of SCOPE.
Example:
}
If SCOPE is "A::B" and SEARCH_PARENTS is true the imports of namespaces X
- and Y will be considered. If SEARCH_PARENTS is false only the import of Y
+ and Y will be considered. If SEARCH_PARENTS is false only the import of Y
is considered. */
-static struct symbol *
+struct symbol *
cp_lookup_symbol_imports (const char *scope,
const char *name,
const struct block *block,
const domain_enum domain,
+ const int declaration_only,
const int search_parents)
{
struct using_direct *current;
- struct symbol *sym;
+ struct symbol *sym = NULL;
int len;
int directive_match;
struct cleanup *searched_cleanup;
/* First, try to find the symbol in the given namespace. */
- sym = cp_lookup_symbol_in_namespace (scope, name, block, domain);
+ if (!declaration_only)
+ sym = cp_lookup_symbol_in_namespace (scope, name, block, domain);
+
if (sym != NULL)
return sym;
current->searched = 1;
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)
+ sym = cp_lookup_symbol_in_namespace (current->import_src,
+ name,
+ block,
+ domain);
+
+ /* If this is a DECLARATION_ONLY search or a symbol was found or
+ this import statement was an import declaration, the search
+ of this import is complete. */
+ if (declaration_only || sym != NULL || current->declaration)
+ {
+ current->searched = 0;
+ discard_cleanups (searched_cleanup);
+
+ if (sym != NULL)
+ return sym;
+
+ continue;
+ }
+
if (current->alias != NULL && strcmp (name, current->alias) == 0)
/* If the import is creating an alias and the alias matches the
sought name. Pass current->import_src as the NAME to direct the
name,
block,
domain,
+ 0,
0);
}
current->searched = 0;
cp_lookup_symbol_namespace (const char *scope,
const char *name,
const struct block *block,
- const domain_enum domain,
- const int search_parents)
+ const domain_enum domain)
{
struct symbol *sym;
+
+ /* First, try to find the symbol in the given namespace. */
+ sym = cp_lookup_symbol_in_namespace (scope, name, block, domain);
+ if (sym != NULL)
+ return sym;
/* Search for name in namespaces imported to this and parent blocks. */
while (block != NULL)
{
- sym = cp_lookup_symbol_imports (scope, name, block, domain,
- search_parents);
+ sym = cp_lookup_symbol_imports (scope, name, block, domain, 0, 1);
if (sym)
return sym;
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.
*/
struct using_direct
char *import_dest;
char *alias;
+ char *declaration;
struct using_direct *next;
extern void cp_add_using_directive (const char *dest,
const char *src,
const char *alias,
+ const char *declaration,
struct obstack *obstack);
extern void cp_initialize_namespace (void);
extern struct symbol *cp_lookup_symbol_namespace (const char *namespace,
const char *name,
const struct block *block,
- const domain_enum domain,
- const int search_parents);
+ const domain_enum domain);
+
+extern struct symbol *cp_lookup_symbol_imports (const char *scope,
+ const char *name,
+ const struct block *block,
+ const domain_enum domain,
+ const int declaration_only,
+ const int search_parents);
extern struct type *cp_lookup_nested_type (struct type *parent_type,
const char *nested_name,
struct dwarf2_cu *imported_cu;
const char *imported_name;
const char *imported_name_prefix;
- char *import_alias;
-
+ const char *canonical_name;
+ const char *import_alias;
+ const char *imported_declaration = NULL;
const char *import_prefix;
- char *canonical_name;
+
+ char *temp;
import_attr = dwarf2_attr (die, DW_AT_import, cu);
if (import_attr == NULL)
to the name of the imported die. */
imported_name_prefix = determine_prefix (imported_die, imported_cu);
- if (strlen (imported_name_prefix) > 0)
+ if (imported_die->tag != DW_TAG_namespace)
{
- canonical_name = alloca (strlen (imported_name_prefix)
- + 2 + strlen (imported_name) + 1);
- strcpy (canonical_name, imported_name_prefix);
- strcat (canonical_name, "::");
- strcat (canonical_name, imported_name);
+ imported_declaration = imported_name;
+ canonical_name = imported_name_prefix;
}
- else
+ else if (strlen (imported_name_prefix) > 0)
{
- canonical_name = alloca (strlen (imported_name) + 1);
- strcpy (canonical_name, imported_name);
+ temp = alloca (strlen (imported_name_prefix)
+ + 2 + strlen (imported_name) + 1);
+ strcpy (temp, imported_name_prefix);
+ strcat (temp, "::");
+ strcat (temp, imported_name);
+ canonical_name = temp;
}
+ else
+ canonical_name = imported_name;
cp_add_using_directive (import_prefix,
canonical_name,
import_alias,
+ imported_declaration,
&cu->objfile->objfile_obstack);
}
{
const char *previous_prefix = determine_prefix (die, cu);
cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
- &objfile->objfile_obstack);
+ NULL, &objfile->objfile_obstack);
}
}
function = cp_lookup_symbol_namespace (TYPE_TAG_NAME (type),
name,
get_selected_block (0),
- VAR_DOMAIN, 1);
+ VAR_DOMAIN);
if (function == NULL)
error (_("No symbol \"%s\" in namespace \"%s\"."),
name, TYPE_TAG_NAME (type));
static
struct symbol *lookup_symbol_aux_local (const char *name,
const struct block *block,
- const domain_enum domain);
+ const domain_enum domain,
+ enum language language);
static
struct symbol *lookup_symbol_aux_symtabs (int block_index,
/* Search specified block and its superiors. Don't search
STATIC_BLOCK or GLOBAL_BLOCK. */
- sym = lookup_symbol_aux_local (name, block, domain);
+ sym = lookup_symbol_aux_local (name, block, domain, language);
if (sym != NULL)
return sym;
/* If requested to do so by the caller and if appropriate for LANGUAGE,
- check to see if NAME is a field of `this'. */
+ check to see if NAME is a field of `this'. */
langdef = language_def (language);
static struct symbol *
lookup_symbol_aux_local (const char *name, const struct block *block,
- const domain_enum domain)
+ const domain_enum domain,
+ enum language language)
{
struct symbol *sym;
const struct block *static_block = block_static_block (block);
-
+ const char *scope = block_scope (block);
+
/* Check if either no block is specified or it's a global block. */
if (static_block == NULL)
if (sym != NULL)
return sym;
+ if (language == language_cplus)
+ {
+ sym = cp_lookup_symbol_imports (scope,
+ name,
+ block,
+ domain,
+ 1,
+ 1);
+ if (sym != NULL)
+ return sym;
+ }
+
if (BLOCK_FUNCTION (block) != NULL && block_inlined_p (block))
break;
block = BLOCK_SUPERBLOCK (block);
+2010-03-15 Sami Wagiaalla <swagiaal@redhat.com>
+
+ * gdb.cp/shadow.exp: Removed kfail; test has been fix.
+ * gdb.cp/nsusing.exp: Ditto.
+
2010-03-15 Tom Tromey <tromey@redhat.com>
* gdb.cp/userdef.exp: Add tests for explicit calls to operator==.
perror "couldn't run to breakpoint marker4"
continue
}
-setup_kfail "gdb/7936" "*-*-*"
+
gdb_test "print dx" "= 4"
############################################
using namespace A;
y++; // marker4
- using A::x;
- y++; // marker5
+ {
+ using A::x;
+ y++; // marker5
+ }
}
}
}
gdb_breakpoint [gdb_get_line_number "marker5"]
gdb_continue_to_breakpoint "marker5"
-setup_kfail "gdb/7936" "*-*-*"
gdb_test "print x" "= 11" "Print imported namespace x"
struct symbol *sym;
struct value *result;
- sym = cp_lookup_symbol_namespace(namespace_name, name,
+ sym = cp_lookup_symbol_namespace (namespace_name, name,
get_selected_block (0),
- VAR_DOMAIN, 1);
+ VAR_DOMAIN);
if (sym == NULL)
return NULL;