]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
2002-10-15 David Carlton <carlton@math.stanford.edu>
authorDavid Carlton <carlton@bactrian.org>
Tue, 15 Oct 2002 23:59:24 +0000 (23:59 +0000)
committerDavid Carlton <carlton@bactrian.org>
Tue, 15 Oct 2002 23:59:24 +0000 (23:59 +0000)
* symtab.c (lookup_symbol_aux_using_loop): prefix_len should be <=
outer_length.
(lookup_symbol_aux_using_loop): Don't skip colons in rest_of_outer
if we've used all of outer.
* cp-support.h: Rename declaration of cp_add_using to
cp_add_using_obstack.
* cp-support.c (cp_add_using_obstack): Rename from cp_add_using.
* buildsym.h: Rename arguments in declaration of
add_using_directive.
* buildsym.c (add_using_directive): Finish definition, rename
arguments.
* cp-support.h: Add declaration for cp_add_using_xmalloc.
* cp-support.c (cp_add_using_xmalloc): New function.
* buildsym.c (copy_usings_to_obstack): New function.
(end_symtab): Set STATIC_BLOCK's BLOCK_USING using
copy_usings_to_obstack.

2002-10-15  David Carlton  <carlton@math.stanford.edu>

* gdb.c++/namespace.exp: Add anonymous namespace tests.
* gdb.c++/namespace.cc: Add anonymous namespaces.

gdb/ChangeLog
gdb/buildsym.c
gdb/buildsym.h
gdb/cp-support.c
gdb/cp-support.h
gdb/symtab.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.c++/namespace.cc
gdb/testsuite/gdb.c++/namespace.exp

index c6ddf0a1bf28bb7fc49c5bf00e6360ba79de8ae3..505e69d1b5f242bc949e28995ebc64ae47ba508f 100644 (file)
@@ -1,21 +1,34 @@
+2002-10-15  David Carlton  <carlton@math.stanford.edu>
+
+       * symtab.c (lookup_symbol_aux_using_loop): prefix_len should be <=
+       outer_length.
+       (lookup_symbol_aux_using_loop): Don't skip colons in rest_of_outer
+       if we've used all of outer.
+       * cp-support.h: Rename declaration of cp_add_using to
+       cp_add_using_obstack.
+       * cp-support.c (cp_add_using_obstack): Rename from cp_add_using.
+       * buildsym.h: Rename arguments in declaration of
+       add_using_directive.
+       * buildsym.c (add_using_directive): Finish definition, rename
+       arguments.
+       * cp-support.h: Add declaration for cp_add_using_xmalloc.
+       * cp-support.c (cp_add_using_xmalloc): New function.
+       * buildsym.c (copy_usings_to_obstack): New function.
+       (end_symtab): Set STATIC_BLOCK's BLOCK_USING using
+       copy_usings_to_obstack.
+
 2002-10-14  David Carlton  <carlton@math.stanford.edu>
 
        * buildsym.c (add_using_directive): Rewrite to match new version
        of struct using_direct.
        (finish_block): Ditto.
-
        * symtab.c (lookup_symbol_aux_using_loop): Add 'prefix_len'
        argument; rewrite to match new version of struct using_direct.
-
        * cp-support.h: Update declaration for cp_add_using.
-
        * cp-support.c (cp_add_using): Rewrite to match new version of
        struct using_direct.
-
        * cp-support.h (struct using_direct): Rewrite struct.
-
        * buildsym.h: Declaration for add_using_directive.
-
        * buildsym.c: New variable 'using_list'.
        (start_symtab): Initialize using_list.
        (end_symtab): Initialize BLOCK_USING of STATIC_BLOCK.
index a2322e24eeb9c96e631425f929b40941f6e4e624..bca5332171dab559ca284b6fdc35029d58642708 100644 (file)
@@ -72,6 +72,12 @@ static struct using_direct_node *using_list;
 static int compare_line_numbers (const void *ln1p, const void *ln2p);
 
 static void scan_for_anonymous_namespaces (struct symbol *symbol);
+
+static struct using_direct_node *copy_usings_to_obstack (struct
+                                                        using_direct_node
+                                                        *usings,
+                                                        struct obstack
+                                                        *obstack);
 \f
 
 /* Initial sizes of data structures.  These are realloc'd larger if
@@ -115,9 +121,9 @@ add_free_pendings (struct pending *list)
     }
 }
       
-/* Add a symbol to one of the lists of symbols.  While we're at it,
-   check to see if it references an anonymous namespace; if so, add an
-   appropriate using directive.  */
+/* Add a symbol to one of the lists of symbols.  While we're at it, if
+   we're in the C++ case, check to see if it references an anonymous
+   namespace; if so, add an appropriate using directive.  */
 
 void
 add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
@@ -151,10 +157,10 @@ add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
 
   /* Check to see if we might need to look for a mention of anonymous
      namespaces.  */
-  /* TODOTODO */
-/*   if (SYMBOL_LANGUAGE (symbol) == language_cplus */
-/*       && SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL) */
-/*     scan_for_anonymous_namespaces (symbol) */
+  
+   if (SYMBOL_LANGUAGE (symbol) == language_cplus
+       && SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL)
+     scan_for_anonymous_namespaces (symbol);
 }
 
 /* Check to see if a symbol is contained within an anonymous
@@ -176,7 +182,7 @@ scan_for_anonymous_namespaces (struct symbol *symbol)
 
   for (beginning = name, end = cp_find_first_component (name);
        *end == ':';
-       /* The "+ 2" is for ':'.  */
+       /* The "+ 2" is for the "::"-.  */
        beginning = end + 2, end = cp_find_first_component (beginning))
     {
       if ((end - beginning) == ANONYMOUS_NAMESPACE_LEN
@@ -219,27 +225,31 @@ find_symbol_in_list (struct pending *list, char *name, int length)
 
 /* This adds a using directive to using_list.  NAME is the start of a
    string that should contain the namespaces we want to add as initial
-   substrings, OUTER_INDEX is the end of the outer namespace, and
-   INNER_INDEX is the end of the inner namespace.  If the using
+   substrings, OUTER_LENGTH is the end of the outer namespace, and
+   INNER_LENGTH is the end of the inner namespace.  If the using
    directive in question has already been added, don't add it
    twice.  */
 
 void
-add_using_directive (const char *name, unsigned int outer_index,
-                    unsigned int inner_index)
+add_using_directive (const char *name, unsigned int outer_length,
+                    unsigned int inner_length)
 {
   struct using_direct_node *current;
+  struct using_direct_node *new_node;
+  struct using_direct *new;
 
-  gdb_assert (outer_index < inner_index);
+  gdb_assert (outer_length < inner_length);
 
   /* Has it already been added?  */
 
   for (current = using_list; current; current = current->next)
-    if (strncmp (current->current->name, name, outer_index) == 0
-       && strncmp (current->current->name, name, inner_index) == 0)
+    if (current->current->outer_length == outer_length
+       && current->current->inner_length == inner_length
+       && (strncmp (current->current->name, name, inner_length) == 0))
       return;
 
-  /* TODOTODO */
+  using_list = cp_add_using_xmalloc (name, outer_length, inner_length,
+                                    using_list);
 }
 
 
@@ -444,8 +454,9 @@ finish_block (struct symbol *symbol, struct pending **listhead,
               next = cp_find_first_component (next + 2))
            {
              BLOCK_USING (block)
-               = cp_add_using (name, 0, next - name, BLOCK_USING (block),
-                               &objfile->symbol_obstack);
+               = cp_add_using_obstack (name, 0, next - name,
+                                       BLOCK_USING (block),
+                                       &objfile->symbol_obstack);
            }
 
          /* FIMXE: carlton/2002-10-09: Until I understand the
@@ -1011,10 +1022,13 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
       finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr,
                    objfile);
       blockvector = make_blockvector (objfile);
-      /* TODOTODO */
-/*       BLOCK_USING (BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK)) */
-/*     = cp_copy_usings_obstack (using_list, &objfile->symbol_obstack); */
-/*       cp_deep_free_usings (using_list); */
+      if (using_list != NULL)
+       {
+         BLOCK_USING (BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK))
+           = copy_usings_to_obstack (using_list,
+                                     &objfile->symbol_obstack);
+         using_list = NULL;
+       }
     }
 
 #ifndef PROCESS_LINENUMBER_HOOK
@@ -1145,6 +1159,32 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
   return symtab;
 }
 
+/* This reallocates USINGS using OBSTACK and xfree's USINGS.  It
+   returns the reallocated version of USINGS.  */
+
+static struct using_direct_node *
+copy_usings_to_obstack (struct using_direct_node *usings,
+                       struct obstack *obstack)
+{
+  if (usings == NULL)
+    return NULL;
+  else
+    {
+      struct using_direct_node *new_node
+       = cp_add_using_obstack (usings->current->name,
+                               usings->current->outer_length,
+                               usings->current->inner_length,
+                               copy_usings_to_obstack (usings->next,
+                                                       obstack),
+                               obstack);
+
+      xfree (usings->current);
+      xfree (usings);
+
+      return new_node;
+    }
+}
+
 /* Search the block for global symbols indicating the presence of
    anonymous namespaces; add using declarations for them, if
    found.  */
index 1e678d0101678ab938f4544a8cd51412139cfc95..28442a7f28f2f2c2f45afad90cc80314d14fd108 100644 (file)
@@ -240,8 +240,8 @@ extern void add_symbol_to_list (struct symbol *symbol,
 extern struct symbol *find_symbol_in_list (struct pending *list,
                                           char *name, int length);
 
-extern void add_using_directive (const char *name, unsigned int outer_index,
-                                unsigned int inner_index);
+extern void add_using_directive (const char *name, unsigned int outer_length,
+                                unsigned int inner_length);
 
 extern void finish_block (struct symbol *symbol,
                          struct pending **listhead,
index d5ca1a1364cc0a5f0db3c78e396247a232a558bf..a13967f9f8292c87055df5abad975f0b57b76218 100644 (file)
@@ -176,11 +176,11 @@ method_name_from_physname (const char *physname)
    using_direct_node.  All memory is allocated using OBSTACK.  */
 
 struct using_direct_node *
-cp_add_using (const char *name,
-             unsigned short outer_length,
-             unsigned short inner_length,
-             struct using_direct_node *next,
-             struct obstack *obstack)
+cp_add_using_obstack (const char *name,
+                     unsigned short outer_length,
+                     unsigned short inner_length,
+                     struct using_direct_node *next,
+                     struct obstack *obstack)
 {
   struct using_direct *current
     = obstack_alloc (obstack, sizeof (struct using_direct));
@@ -198,8 +198,33 @@ cp_add_using (const char *name,
   return retval;
 }
 
+/* Same as cp_add_using, except that it uses xmalloc instead of
+   obstacks.  */
+
+struct using_direct_node *
+cp_add_using_xmalloc (const char *name,
+                     unsigned short outer_length,
+                     unsigned short inner_length,
+                     struct using_direct_node *next)
+{
+  struct using_direct *current = xmalloc (sizeof (struct using_direct));
+  struct using_direct_node *retval
+    = xmalloc (sizeof (struct using_direct_node));
+
+  gdb_assert (outer_length < inner_length);
+
+  current->name = name;
+  current->outer_length = outer_length;
+  current->inner_length = inner_length;
+  retval->current = current;
+  retval->next = next;
+
+  return retval;
+}
+
 /* This copies the using_direct_nodes in TOCOPY, using xmalloc, and
-   sticks them onto a list ending in TAIL.  */
+   sticks them onto a list ending in TAIL.  (It doesn't copy the
+   using_directs, just the using_direct_nodes.)  */
 
 struct using_direct_node *
 cp_copy_usings (struct using_direct_node *tocopy,
index 31eab6e3ba652ca6c8ac666736178f2f148b2a80..bb89c6fe26f7ed097f4d095fecc24489b5c47aa3 100644 (file)
@@ -67,11 +67,19 @@ struct using_direct_node
   struct using_direct_node *next;
 };
 
-extern struct using_direct_node *cp_add_using (const char *name,
-                                              unsigned short outer_length,
-                                              unsigned short inner_length,
-                                              struct using_direct_node *next,
-                                              struct obstack *obstack);
+extern struct
+using_direct_node *cp_add_using_obstack (const char *name,
+                                        unsigned short outer_length,
+                                        unsigned short inner_length,
+                                        struct using_direct_node *next,
+                                        struct obstack *obstack);
+
+extern
+struct using_direct_node *cp_add_using_xmalloc (const char *name,
+                                               unsigned short outer_length,
+                                               unsigned short inner_length,
+                                               struct using_direct_node
+                                               *next);
 
 extern
 struct using_direct_node *cp_copy_usings (struct using_direct_node *tocopy,
index 5db5b6a559b55c6b53defb3ddc4c7a95a1f566ef..390c7643c47cde3125b203de84579279fff69403 100644 (file)
@@ -1114,7 +1114,7 @@ lookup_symbol_aux_using_loop (const char *prefix,
     {
       /* First, see if the prefix matches the start of this using
         directive.  */
-      if (prefix_len >= current->current->outer_length
+      if (prefix_len <= current->current->outer_length
          && strncmp (prefix, current->current->name, prefix_len) == 0)
        {
          /* Great, it matches: now does the rest of the using
@@ -1123,10 +1123,10 @@ lookup_symbol_aux_using_loop (const char *prefix,
          const char *rest_of_outer = current->current->name + prefix_len;
          int rest_of_outer_len
            = current->current->outer_length - prefix_len;
-         /* Should we skip some colons?  (Should always be true
-            unless PREFIX_LEN is zero (and hence we're in the global
-            namespace.)  */
-         if (*rest_of_outer == ':')
+         /* Should we skip some colons?  Should be true unless
+            PREFIX_LEN is zero (and hence we're in the global
+            namespace) or we've finished all of outer.  */
+         if (rest_of_outer_len != 0 && *rest_of_outer == ':')
            {
              rest_of_outer += 2;
              rest_of_outer_len -= 2;
index 43a345550fe251b259469538a40a331828b2ed59..5ca6345e15fc1432cf347615d87dd940f658a8fa 100644 (file)
@@ -1,3 +1,8 @@
+2002-10-15  David Carlton  <carlton@math.stanford.edu>
+
+       * gdb.c++/namespace.exp: Add anonymous namespace tests.
+       * gdb.c++/namespace.cc: Add anonymous namespaces.
+
 2002-10-11  David Carlton  <carlton@math.stanford.edu>
 
        * gdb.c++/namespace.exp: Add tests from within C::D::marker2.
index 76b8a36b12b0a679ce63679083bab605b20e1394..c5ec895f5ef66fc94bc743a232f879f3ed0a3d55 100644 (file)
@@ -68,10 +68,40 @@ void marker1(void)
   return;
 }
 
+namespace
+{
+  int X = 9;
+
+  namespace G
+  {
+    int Xg = 10;
+
+    namespace
+    {
+      int XgX = 11;
+    }
+  }
+}
+
 namespace C
 {
   int c = 1;
 
+  namespace
+  {
+    int cX = 6;
+    
+    namespace F
+    {
+      int cXf = 7;
+
+      namespace
+      {
+       int cXfX = 8;
+      }
+    }
+  }
+
   namespace C
   {
     int cc = 2;
@@ -103,13 +133,18 @@ namespace C
       cd;
       E::cde;
       //E::ce;
+      cX;
+      F::cXf;
+      F::cXfX;
+      X;
+      G::Xg;
+      G::XgX;
       return;
     }
 
   }
 }
 
-
 int main ()
 {
   using AAA::inA;
index e87425b26d14923b680ec75e56a90dd9d5a68622..30a68fe2adfa56c6937b1e5018b1c429cdd90b43 100644 (file)
@@ -205,3 +205,10 @@ gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5" "print E::cde"
 # FIXME: carlton/2002-10-11: It would be nice to test printing
 # "E::ce", but unfortunately GDB will print it out even though it
 # shouldn't.  Oops.
+
+gdb_test "print cX" "\\$\[0-9\].* = 6" "print cX"
+gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7" "print F::cXf"
+gdb_test "print 'F::cXfX'" "\\$\[0-9\].* = 8" "print F::cXfX"
+gdb_test "print X" "\\$\[0-9\].* = 9" "print X"
+gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10" "print G::Xg"
+gdb_test "print 'G::XgX'" "\\$\[0-9\].* = 11" "print G::XgX"