Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Sami Wagiaalla <swagiaal@redhat.com>
To: gdb-patches@sourceware.org
Subject: Re: [patch 2/2] Perform a namespace lookup at every block level
Date: Tue, 24 Nov 2009 19:12:00 -0000	[thread overview]
Message-ID: <4B0C3011.4080000@redhat.com> (raw)
In-Reply-To: <4B019120.7090504@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 7456 bytes --]

Updating patch because of changes in patch 1/2



2009-11-16  Sami Wagiaalla  <swagiaal@redhat.com>
       * cp-namespace.c (cp_lookup_symbol_namespace): Added
       search_parent argument.
       (cp_add_using): Initialize 'searched' field.
       (cp_copy_usings): Copy searched field.
       * cp-support.h: Add 'searched' field to using_direct struct.
       (cp_lookup_symbol_imports): Ditto.
       * cp-namespace.c (cp_lookup_symbol_imports): Ditto.
       Perform recursive search.
       Implement non parent search.
       * valops.c (value_maybe_namespace_elt): Updated.

2009-11-16  Sami Wagiaalla  <swagiaal@redhat.com>
       * gdb.cp/namespace-stress.exp: New test.
       * gdb.cp/namespace-stress.cc: New test program.
       * gdb.cp/namespace-recursive.exp: New test.
       * gdb.cp/namespace-recursive.cc: New test program.
       * gdb.cp/namespace-stress.exp: New test.
       * gdb.cp/namespace-stress.cc: New test program.

diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index f63cf8a..e2f1d43 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -217,6 +217,7 @@ cp_add_using (const char *dest,
    retval->import_src = savestring (src, strlen(src));
    retval->import_dest = savestring (dest, strlen(dest));
    retval->next = next;
+  retval->searched = 0;
  
    return retval;
  }
@@ -243,6 +244,8 @@ cp_copy_usings (struct using_direct *using,
  				    obstack);
        retval->next = cp_copy_usings (using->next, obstack);
  
+      retval->searched = using->searched;
+
        xfree (using->import_src);
        xfree (using->import_dest);
        xfree (using);
@@ -272,7 +275,8 @@ cp_lookup_symbol_nonlocal (const char *name,
    if (sym != NULL)
      return sym;
  
-  return cp_lookup_symbol_namespace (scope, name, linkage_name, block, domain);
+  return cp_lookup_symbol_namespace (scope, name, linkage_name, block, domain,
+                                     1);
  }
  
  /* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in
@@ -302,19 +306,46 @@ cp_lookup_symbol_in_namespace (const char *namespace,
      }
  }
  
-/* Search for NAME by applying all import statements belonging
-   to BLOCK which are applicable in SCOPE.  */
+/* Used for cleanups to reset the "searched" flag incase
+   of an error.  */
+
+static void
+reset_directive_searched (void *data)
+{
+  struct using_direct *direct = data;
+  direct->searched = 0;
+}
  
+/* Search for NAME by applying all import statements belonging
+   to BLOCK which are applicable in SCOPE.
+   If SEARCH_PARENTS the search will include imports which are applicable in
+   parents of SCOPE.
+   Example:
+
+     namespace A{
+       using namespace X;
+       namespace B{
+         using namespace Y;
+       }
+     }
+
+   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
+   is considered.  */
+
  static struct symbol *
  cp_lookup_symbol_imports (const char *scope,
                            const char *name,
                            const char *linkage_name,
                            const struct block *block,
-                          const domain_enum domain)
+                          const domain_enum domain,
+                          const int search_parents)
  {
-  const struct using_direct *current;
+  struct using_direct *current;
    struct symbol *sym;
    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, linkage_name, block,
@@ -330,24 +361,41 @@ cp_lookup_symbol_imports (const char *scope,
         current != NULL;
         current = current->next)
      {
+      len = strlen (current->import_dest);
+      directive_match = (search_parents
+                         ? (strncmp (scope, current->import_dest,
+                                     strlen (current->import_dest)) == 0
+                            && (len == 0
+                        	 || scope[len] == ':' || scope[len] == '\0'))
+                         : strcmp (scope, current->import_dest) == 0);
  
        /* If the import destination is the current scope or one of its ancestors then
           it is applicable.  */
-      len = strlen (current->import_dest);
-      if (strncmp (scope, current->import_dest, len) == 0
-	  && (len == 0 || scope[len] == ':' || scope[len] == '\0'))
+      if (directive_match && !current->searched)
  	{
-	  sym = cp_lookup_symbol_in_namespace (current->import_src, name,
-					       linkage_name, block, domain);
-	  if (sym != NULL)
-	    return sym;
+	/* Mark this import as searched so that the recursive call does not
+          search it again.  */
+	current->searched = 1;
+	searched_cleanup = make_cleanup (reset_directive_searched, current);
+
+	sym = cp_lookup_symbol_namespace (current->import_src,
+	                                  name,
+	                                  linkage_name,
+	                                  block,
+	                                  domain,
+	                                  0);
+
+	current->searched = 0;
+	discard_cleanups (searched_cleanup);
+
+	if (sym != NULL)
+	  return sym;
  	}
      }
  
    return NULL;
  }
  
-
   /* Searches for NAME in the current namespace, and by applying relevant import
      statements belonging to BLOCK and its parents. SCOPE is the namespace scope
      of the context in which the search is being evaluated.  */
@@ -357,14 +405,16 @@ cp_lookup_symbol_namespace (const char *scope,
                              const char *name,
                              const char *linkage_name,
                              const struct block *block,
-                            const domain_enum domain)
+                            const domain_enum domain,
+                            const int search_parents)
  {
    struct symbol *sym;
  
    /* Search for name in namespaces imported to this and parent blocks.  */
    while (block != NULL)
      {
-      sym = cp_lookup_symbol_imports (scope,name, linkage_name, block, domain);
+      sym = cp_lookup_symbol_imports (scope, name, linkage_name, block, domain,
+                                      search_parents);
  
        if (sym)
  	return sym;
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index 7ecd201..9400469 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -47,6 +47,9 @@ struct using_direct
    char *import_src;
    char *import_dest;
    struct using_direct *next;
+
+  /* Used during import search to temporarily mark this node as searched.  */
+  int searched;
  };
  
  
@@ -107,7 +110,8 @@ extern struct symbol *cp_lookup_symbol_namespace (const char *namespace,
  						  const char *name,
  						  const char *linkage_name,
  						  const struct block *block,
-						  const domain_enum domain);
+						  const domain_enum domain,
+						  const int search_parents);
  
  extern struct type *cp_lookup_nested_type (struct type *parent_type,
  					   const char *nested_name,
diff --git a/gdb/valops.c b/gdb/valops.c
index 012ea6a..6fdea95 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -2765,7 +2765,7 @@ value_maybe_namespace_elt (const struct type *curtype,
  
    sym = cp_lookup_symbol_namespace (namespace_name, name, NULL,
  				    get_selected_block (0),
-				    VAR_DOMAIN);
+				    VAR_DOMAIN, 1);
  
    if (sym == NULL)
      return NULL;

[-- Attachment #2: sami2-recursive-search.patch --]
[-- Type: text/plain, Size: 7316 bytes --]


2009-11-16  Sami Wagiaalla  <swagiaal@redhat.com>
      * cp-namespace.c (cp_lookup_symbol_namespace): Added
      search_parent argument.
      (cp_add_using): Initialize 'searched' field.
      (cp_copy_usings): Copy searched field.
      * cp-support.h: Add 'searched' field to using_direct struct.
      (cp_lookup_symbol_imports): Ditto.
      * cp-namespace.c (cp_lookup_symbol_imports): Ditto.
      Perform recursive search.
      Implement non parent search.
      * valops.c (value_maybe_namespace_elt): Updated.

2009-11-16  Sami Wagiaalla  <swagiaal@redhat.com>
      * gdb.cp/namespace-stress.exp: New test.
      * gdb.cp/namespace-stress.cc: New test program.
      * gdb.cp/namespace-recursive.exp: New test.
      * gdb.cp/namespace-recursive.cc: New test program.
      * gdb.cp/namespace-stress.exp: New test.
      * gdb.cp/namespace-stress.cc: New test program.

diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index f63cf8a..e2f1d43 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -217,6 +217,7 @@ cp_add_using (const char *dest,
   retval->import_src = savestring (src, strlen(src));
   retval->import_dest = savestring (dest, strlen(dest));
   retval->next = next;
+  retval->searched = 0;
 
   return retval;
 }
@@ -243,6 +244,8 @@ cp_copy_usings (struct using_direct *using,
 				    obstack);
       retval->next = cp_copy_usings (using->next, obstack);
 
+      retval->searched = using->searched;
+
       xfree (using->import_src);
       xfree (using->import_dest);
       xfree (using);
@@ -272,7 +275,8 @@ cp_lookup_symbol_nonlocal (const char *name,
   if (sym != NULL)
     return sym;
 
-  return cp_lookup_symbol_namespace (scope, name, linkage_name, block, domain);
+  return cp_lookup_symbol_namespace (scope, name, linkage_name, block, domain,
+                                     1);
 }
 
 /* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in
@@ -302,19 +306,46 @@ cp_lookup_symbol_in_namespace (const char *namespace,
     }
 }
 
-/* Search for NAME by applying all import statements belonging
-   to BLOCK which are applicable in SCOPE.  */
+/* Used for cleanups to reset the "searched" flag incase
+   of an error.  */
+
+static void
+reset_directive_searched (void *data)
+{
+  struct using_direct *direct = data;
+  direct->searched = 0;
+}
 
+/* Search for NAME by applying all import statements belonging
+   to BLOCK which are applicable in SCOPE.
+   If SEARCH_PARENTS the search will include imports which are applicable in
+   parents of SCOPE.
+   Example:
+
+     namespace A{
+       using namespace X;
+       namespace B{
+         using namespace Y;
+       }
+     }
+
+   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
+   is considered.  */
+  
 static struct symbol *
 cp_lookup_symbol_imports (const char *scope,
                           const char *name,
                           const char *linkage_name,
                           const struct block *block,
-                          const domain_enum domain)
+                          const domain_enum domain,
+                          const int search_parents)
 {
-  const struct using_direct *current;
+  struct using_direct *current;
   struct symbol *sym;
   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, linkage_name, block,
@@ -330,24 +361,41 @@ cp_lookup_symbol_imports (const char *scope,
        current != NULL;
        current = current->next)
     {
+      len = strlen (current->import_dest);
+      directive_match = (search_parents
+                         ? (strncmp (scope, current->import_dest,
+                                     strlen (current->import_dest)) == 0
+                            && (len == 0 
+                        	 || scope[len] == ':' || scope[len] == '\0'))
+                         : strcmp (scope, current->import_dest) == 0);
 
       /* If the import destination is the current scope or one of its ancestors then
          it is applicable.  */
-      len = strlen (current->import_dest);
-      if (strncmp (scope, current->import_dest, len) == 0
-	  && (len == 0 || scope[len] == ':' || scope[len] == '\0'))
+      if (directive_match && !current->searched)
 	{
-	  sym = cp_lookup_symbol_in_namespace (current->import_src, name,
-					       linkage_name, block, domain);
-	  if (sym != NULL)
-	    return sym;
+	/* Mark this import as searched so that the recursive call does not
+          search it again.  */
+	current->searched = 1;
+	searched_cleanup = make_cleanup (reset_directive_searched, current);
+
+	sym = cp_lookup_symbol_namespace (current->import_src,
+	                                  name,
+	                                  linkage_name,
+	                                  block,
+	                                  domain,
+	                                  0);
+
+	current->searched = 0;
+	discard_cleanups (searched_cleanup);
+
+	if (sym != NULL)
+	  return sym;
 	}
     }
 
   return NULL;
 }
 
-
  /* Searches for NAME in the current namespace, and by applying relevant import
     statements belonging to BLOCK and its parents. SCOPE is the namespace scope
     of the context in which the search is being evaluated.  */
@@ -357,14 +405,16 @@ cp_lookup_symbol_namespace (const char *scope,
                             const char *name,
                             const char *linkage_name,
                             const struct block *block,
-                            const domain_enum domain)
+                            const domain_enum domain,
+                            const int search_parents)
 {
   struct symbol *sym;
 
   /* Search for name in namespaces imported to this and parent blocks.  */
   while (block != NULL)
     {
-      sym = cp_lookup_symbol_imports (scope,name, linkage_name, block, domain);
+      sym = cp_lookup_symbol_imports (scope, name, linkage_name, block, domain,
+                                      search_parents);
 
       if (sym)
 	return sym;
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index 7ecd201..9400469 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -47,6 +47,9 @@ struct using_direct
   char *import_src;
   char *import_dest;
   struct using_direct *next;
+
+  /* Used during import search to temporarily mark this node as searched.  */
+  int searched;
 };
 
 
@@ -107,7 +110,8 @@ extern struct symbol *cp_lookup_symbol_namespace (const char *namespace,
 						  const char *name,
 						  const char *linkage_name,
 						  const struct block *block,
-						  const domain_enum domain);
+						  const domain_enum domain,
+						  const int search_parents);
 
 extern struct type *cp_lookup_nested_type (struct type *parent_type,
 					   const char *nested_name,
diff --git a/gdb/valops.c b/gdb/valops.c
index 012ea6a..6fdea95 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -2765,7 +2765,7 @@ value_maybe_namespace_elt (const struct type *curtype,
 
   sym = cp_lookup_symbol_namespace (namespace_name, name, NULL,
 				    get_selected_block (0), 
-				    VAR_DOMAIN);
+				    VAR_DOMAIN, 1);
 
   if (sym == NULL)
     return NULL;

  reply	other threads:[~2009-11-24 19:12 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-10 15:10 [patch] " Sami Wagiaalla
2009-07-10 20:16 ` Daniel Jacobowitz
2009-07-13 17:55   ` Sami Wagiaalla
2009-07-23 19:46     ` Sami Wagiaalla
2009-07-23 22:19       ` Sami Wagiaalla
2009-07-29 22:12       ` Tom Tromey
2009-08-18 20:34       ` [patch 1/2] " Sami Wagiaalla
2009-10-13 19:47         ` Tom Tromey
2009-10-20 20:50           ` Sami Wagiaalla
2009-11-10 22:23             ` Tom Tromey
2009-11-10 22:26               ` Tom Tromey
2009-11-16 15:32                 ` Sami Wagiaalla
2009-11-16 19:16                   ` Sami Wagiaalla
2009-11-24 19:06                   ` Sami Wagiaalla
2009-12-21 21:44                     ` Tom Tromey
2009-08-18 20:46       ` [patch 2/2] " Sami Wagiaalla
2009-09-04 16:57         ` Sami Wagiaalla
2009-10-13 20:22           ` Tom Tromey
2009-10-22 17:47             ` Sami Wagiaalla
2009-11-10 22:52               ` Tom Tromey
2009-11-16 17:55                 ` Sami Wagiaalla
2009-11-24 19:12                   ` Sami Wagiaalla [this message]
2009-12-21 21:55                     ` Tom Tromey
2010-01-11 21:24                       ` Sami Wagiaalla
2010-01-12 17:43                         ` Tom Tromey
2010-01-14 16:47                           ` Sami Wagiaalla
2010-01-14 20:18                             ` Sami Wagiaalla
2010-01-15 18:06                               ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B0C3011.4080000@redhat.com \
    --to=swagiaal@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox