]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
2002-11-14 David Carlton <carlton@math.stanford.edu>
authorDavid Carlton <carlton@bactrian.org>
Fri, 15 Nov 2002 01:10:43 +0000 (01:10 +0000)
committerDavid Carlton <carlton@bactrian.org>
Fri, 15 Nov 2002 01:10:43 +0000 (01:10 +0000)
* Makefile.in (symtab.o): Depend on gdb_assert_h.
* symtab.c: #include "gdb_assert.h"
* Makefile.in (namespace): Add 'namespace' target.
* buildsym.c (finish_block): Comment out the using declarations
generation.
* block.h: Make argument to block_scope const.
* block.c (block_scope): Make argument const.
* symtab.c (lookup_symbol_aux_using): Gather usings via
block_all_usings.
(lookup_symbol_namespace): Rename from
lookup_symbol_aux_using_loop.
(lookup_symbol_aux_using_loop): New function.
* block.h: Declare block_all_usings.
* block.c (block_all_usings): New function.
* symtab.c (lookup_symbol_aux_nonlocal): Delete FIXME comment.
* buildsym.c (finish_block): Add FIXME comment.

2002-11-14  David Carlton  <carlton@math.stanford.edu>

* carlton_runnamespace: New file.

gdb/ChangeLog
gdb/Makefile.in
gdb/block.c
gdb/block.h
gdb/buildsym.c
gdb/symtab.c
gdb/testsuite/ChangeLog
gdb/testsuite/carlton_runnamespace [new file with mode: 0755]

index 82304c269578717bef03e64894f8891dbf89efb5..2b1233c94b92dfcd60a1625baa2ab1e0a9830c74 100644 (file)
@@ -1,3 +1,22 @@
+2002-11-14  David Carlton  <carlton@math.stanford.edu>
+
+       * Makefile.in (symtab.o): Depend on gdb_assert_h.
+       * symtab.c: #include "gdb_assert.h"
+       * Makefile.in (namespace): Add 'namespace' target.
+       * buildsym.c (finish_block): Comment out the using declarations
+       generation.
+       * block.h: Make argument to block_scope const.
+       * block.c (block_scope): Make argument const.
+       * symtab.c (lookup_symbol_aux_using): Gather usings via
+       block_all_usings.
+       (lookup_symbol_namespace): Rename from
+       lookup_symbol_aux_using_loop.
+       (lookup_symbol_aux_using_loop): New function.
+       * block.h: Declare block_all_usings.
+       * block.c (block_all_usings): New function.
+       * symtab.c (lookup_symbol_aux_nonlocal): Delete FIXME comment.
+       * buildsym.c (finish_block): Add FIXME comment.
+
 2002-11-13  David Carlton  <carlton@math.stanford.edu>
 
        * buildsym.c (finish_block): Initialize block_scope (block) in
index 266dd97742c493ee33b217e74709575f82e2aa0a..91316a9c8177aa1308d99e5878aed90054b42552 100644 (file)
@@ -2222,7 +2222,7 @@ symtab.o: symtab.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(gdbcore_h) \
        $(language_h) $(demangle_h) $(inferior_h) $(linespec_h)   \
        $(filenames_h) $(dictionary_h) $(gdb_obstack_h)           \
        $(gdb_string_h) $(gdb_stat_h) $(cp_abi_h) $(source_h) $(cp_support_h) \
-       $(block_h)
+       $(block_h) $(gdb_assert_h)
 target.o: target.c $(defs_h) $(gdb_string_h) $(target_h) $(gdbcmd_h) \
        $(symtab_h) $(inferior_h) $(bfd_h) $(symfile_h) $(objfiles_h) \
        $(gdb_wait_h) $(dcache_h) $(regcache_h)
@@ -2659,4 +2659,7 @@ xdr_rdb.o: vx-share/xdr_rdb.c $(defs_h) vx-share/vxTypes.h \
 carlton: all
        cd testsuite; ./carlton_runtest
 
+namespace: all
+       cd testsuite; ./carlton_runnamespace
+
 ### end of the gdb Makefile.in.
index f7161aef611dea6d9e102813a9ee9ca92863ab81..7becf2e9f94b9197bc49898437dd33cb6cb039ac 100644 (file)
@@ -66,6 +66,25 @@ block_using (const struct block *block)
     return BLOCK_NAMESPACE (block)->using;
 }
 
+/* This returns the using directives associated to BLOCK and its
+   parents, if any.  The resulting structure must be freed by calling
+   cp_free_usings on it.  */
+
+struct using_direct_node *
+block_all_usings (const struct block *block)
+{
+  struct using_direct_node *using = NULL;
+
+  while (block != NULL)
+    {
+      using = cp_copy_usings (block_using (block), using);
+      block = BLOCK_SUPERBLOCK (block);
+    }
+
+  return using;
+}
+
+
 /* Set block_using (BLOCK) to USING; if needed, allocate memory via
    OBSTACK.  */
 
@@ -83,7 +102,7 @@ block_set_using (struct block *block, struct using_direct_node *using,
    superblocks looking for a scope, if necessary.  */
 
 const char *
-block_scope (struct block *block)
+block_scope (const struct block *block)
 {
   for (; block != NULL; block = BLOCK_SUPERBLOCK (block))
     {
index 9ad53af7826a75db75e37c881027ef04a9a510ec..d0700c1fb616bfc89f1d29ffdcebecb35cf7982a 100644 (file)
@@ -139,11 +139,13 @@ extern int contained_in (struct block *, struct block *);
 
 extern struct using_direct_node *block_using (const struct block *);
 
+extern struct using_direct_node *block_all_usings (const struct block *block);
+
 extern void block_set_using (struct block *block,
                             struct using_direct_node *using,
                             struct obstack *obstack);
 
-extern const char *block_scope (struct block *block);
+extern const char *block_scope (const struct block *block);
 
 extern void block_set_scope (struct block *block, const char *scope,
                             struct obstack *obstack);
index 6a0433fe16b00c6d0439cebfb5cbf067945676db..b786536695c985aff68b2305c89b6ca6d048c010 100644 (file)
@@ -454,6 +454,10 @@ finish_block (struct symbol *symbol, struct pending **listhead,
          else
            {
              const char *current, *next;
+
+             /* FIXME: carlton/2002-11-14: For members of classes,
+                with this include the class name as well?  I don't
+                think that's a problem yet, but it will be.  */
              
              for (current = name, next = cp_find_first_component (current);
                   *next == ':';
@@ -468,8 +472,14 @@ finish_block (struct symbol *symbol, struct pending **listhead,
                                 obsavestring (name, current - name,
                                               &objfile->symbol_obstack),
                                 &objfile->symbol_obstack);
+             
+             /* FIXME: carlton/2002-10-09: Until I understand the
+                possible pitfalls of demangled names a lot better, I
+                want to make sure I'm not running into surprises.  */
+             gdb_assert (*next == '\0');
            }
          
+#if 0    
          for (next = cp_find_first_component (name);
               *next == ':';
               /* The '+ 2' is to skip the '::'.  */
@@ -481,11 +491,7 @@ finish_block (struct symbol *symbol, struct pending **listhead,
                                                     &objfile->symbol_obstack),
                               &objfile->symbol_obstack);
            }
-
-         /* FIXME: carlton/2002-10-09: Until I understand the
-            possible pitfalls of demangled names a lot better, I want
-            to make sure I'm not running into surprises.  */
-         gdb_assert (*next == '\0');
+#endif
        }
     }
   else
index 73c3b215629c1755d5765c18ffd3f1c3d79740c8..3f2c1ffb9f55cd08a18924575cf9826cab6d09f2 100644 (file)
@@ -52,6 +52,7 @@
 #include <ctype.h>
 #include "cp-abi.h"
 #include "cp-support.h"
+#include "gdb_assert.h"
 
 /* Prototypes for local functions */
 
@@ -130,13 +131,21 @@ struct symbol *lookup_symbol_aux_using (const char *name,
                                        struct symtab **symtab);
 
 static
-struct symbol *lookup_symbol_aux_using_loop (const char *prefix,
-                                            int prefix_len,
-                                            const char *rest,
-                                            struct using_direct_node *using,
+struct symbol *lookup_symbol_aux_using_loop (const char *name,
                                             const char *mangled_name,
                                             namespace_enum namespace,
-                                            struct symtab **symtab);
+                                            struct symtab **symtab,
+                                            const char *scope,
+                                            int scope_len,
+                                            struct using_direct_node *using);
+static
+struct symbol *lookup_symbol_namespace (const char *prefix,
+                                       int prefix_len,
+                                       const char *rest,
+                                       struct using_direct_node *using,
+                                       const char *mangled_name,
+                                       namespace_enum namespace,
+                                       struct symtab **symtab);
 
 static
 struct symbol *lookup_symbol_aux_minsyms (int block_index,
@@ -997,9 +1006,6 @@ lookup_symbol_aux_block (const char *name, const char *mangled_name,
    STATIC_BLOCK, depending on whether or not we want to search global
    symbols or static symbols.  */
 
-/* FIXME: carlton/2002-10-11: Should this also do some minsym
-   lookup?  */
-
 static struct symbol *
 lookup_symbol_aux_nonlocal (int block_index,
                            const char *name,
@@ -1169,32 +1175,69 @@ lookup_symbol_aux_psymtabs (int block_index, const char *name,
 /* This function gathers using directives from BLOCK and its
    superblocks, and then searches for symbols in the global namespace
    by trying to apply those various using directives.  */
+
 static struct symbol *lookup_symbol_aux_using (const char *name,
                                               const char *mangled_name,
                                               const struct block *block,
                                               const namespace_enum namespace,
                                               struct symtab **symtab)
 {
-  struct using_direct_node *using = NULL;
+  struct using_direct_node *using;
+  const char *scope;
   struct symbol *sym;
 
-  while (block != NULL)
-    {
-      using = cp_copy_usings (block_using (block), using);
-      block = BLOCK_SUPERBLOCK (block);
-    }
-
-  sym = lookup_symbol_aux_using_loop ("", 0, name, using, mangled_name,
-                                     namespace, symtab);
+  using = block_all_usings (block);
+  scope = block_scope (block);
+  
+  sym = lookup_symbol_aux_using_loop (name, mangled_name, namespace, symtab,
+                                     scope, 0, using);
   cp_free_usings (using);
   
   return sym;
 }
 
+/* Look up NAME in the namespaces given by SCOPE and its initial
+   prefixes, applying using directives given by USING; only consider
+   prefixes that are at least as long as SCOPE_LEN, however.  Look up
+   longest prefixes first.  */
+
+static struct
+symbol *lookup_symbol_aux_using_loop (const char *name,
+                                     const char *mangled_name,
+                                     namespace_enum namespace,
+                                     struct symtab **symtab,
+                                     const char *scope,
+                                     int scope_len,
+                                     struct using_direct_node *using)
+{
+  if (scope[scope_len] != '\0')
+    {
+      struct symbol *sym;
+      int next_component;
+      int new_scope_len = scope_len;
+
+      /* If the current scope is followed by "::", skip past that.  */
+      if (new_scope_len != 0)
+       {
+         gdb_assert (scope[new_scope_len] == ':');
+         new_scope_len += 2;
+       }
+      next_component = cp_find_first_component (scope + new_scope_len) - scope;
+      sym = lookup_symbol_aux_using_loop (name, mangled_name, namespace,
+                                         symtab, scope, next_component,
+                                         using);
+      if (sym != NULL)
+       return sym;
+    }
+
+  return lookup_symbol_namespace (scope, scope_len, name, using,
+                                 mangled_name, namespace, symtab);
+}
+
 /* This tries to look up REST in the namespace given by the initial
    substring of PREFIX of length PREFIX_LEN.
 
-   Basically, assume that we have using directives adding A to the
+   For example, assume that we have using directives adding A to the
    global namespace, adding A::inner to namespace A, and adding B to
    the global namespace.  Then, when looking up a symbol "foo", we
    want to recurse by looking up stuff in A::foo and seeing which
@@ -1216,13 +1259,13 @@ static struct symbol *lookup_symbol_aux_using (const char *name,
    for other reasons, but it will take a little while.)  */
 
 static struct symbol *
-lookup_symbol_aux_using_loop (const char *prefix,
-                             int prefix_len,
-                             const char *rest,
-                             struct using_direct_node *using,
-                             const char *mangled_name,
-                             namespace_enum namespace,
-                             struct symtab **symtab)
+lookup_symbol_namespace (const char *prefix,
+                        int prefix_len,
+                        const char *rest,
+                        struct using_direct_node *using,
+                        const char *mangled_name,
+                        namespace_enum namespace,
+                        struct symtab **symtab)
 {
   struct using_direct_node *current;
   struct symbol *sym;
@@ -1256,14 +1299,13 @@ lookup_symbol_aux_using_loop (const char *prefix,
              if (*new_rest == ':')
                new_rest += 2;
 
-             sym = lookup_symbol_aux_using_loop
-               (current->current->name,
-                current->current->inner_length,
-                new_rest,
-                using,
-                mangled_name,
-                namespace,
-                symtab);
+             sym = lookup_symbol_namespace (current->current->name,
+                                            current->current->inner_length,
+                                            new_rest,
+                                            using,
+                                            mangled_name,
+                                            namespace,
+                                            symtab);
              if (sym != NULL)
                return sym;
            }
index fe239984e44c51f25baba4831b609745cce181ba..a54cbdd7df64a54e6a46918f0973b4ce5891b90d 100644 (file)
@@ -1,3 +1,7 @@
+2002-11-14  David Carlton  <carlton@math.stanford.edu>
+
+       * carlton_runnamespace: New file.
+
 2002-10-22  Daniel Jacobowitz  <drow@mvista.com>
 
        * gdb.threads/schedlock.c (args): Make unsigned.
diff --git a/gdb/testsuite/carlton_runnamespace b/gdb/testsuite/carlton_runnamespace
new file mode 100755 (executable)
index 0000000..fb37149
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+# Just run the namespace test.
+
+runtest namespace.exp 2>&1 | grep -v "^Test Run By" > /tmp/namespaceout
+diff -u {carlton_,/tmp/}namespaceout