Use std::vector in add_using_directive
authorTom Tromey <tom@tromey.com>
Wed, 6 Sep 2017 23:18:23 +0000 (17:18 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 9 Sep 2017 20:10:51 +0000 (14:10 -0600)
This changes add_using_directive to accept a std::vector and then
changes the callers.  This allows removing a cleanup.

ChangeLog
2017-09-09  Tom Tromey  <tom@tromey.com>

* namespace.h (add_using_directive): Update.
* namespace.c (add_using_directive): Change type of excludes to
std::vector.
* dwarf2read.c (read_import_statement): Use std::vector.
(read_namespace): Update.
* cp-namespace.c (cp_scan_for_anonymous_namespaces): Update.

gdb/ChangeLog
gdb/cp-namespace.c
gdb/dwarf2read.c
gdb/namespace.c
gdb/namespace.h

index c05692473499cf41e65f8fb7161eb74e21c7bfd6..1bcc95a3cda9c5c6eaebbcc104f665352b5d4257 100644 (file)
@@ -1,3 +1,12 @@
+2017-09-09  Tom Tromey  <tom@tromey.com>
+
+       * namespace.h (add_using_directive): Update.
+       * namespace.c (add_using_directive): Change type of excludes to
+       std::vector.
+       * dwarf2read.c (read_import_statement): Use std::vector.
+       (read_namespace): Update.
+       * cp-namespace.c (cp_scan_for_anonymous_namespaces): Update.
+
 2017-09-09  Tom Tromey  <tom@tromey.com>
 
        * linespec.c (create_sals_line_offset): Use gdb::def_vector.
index f27783ae5ac48c67d8a61b34dd5fca6f22cb8518..90ff51395433aec1f368c26e20a68699324e8616 100644 (file)
@@ -93,8 +93,9 @@ cp_scan_for_anonymous_namespaces (const struct symbol *const symbol,
                 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.  */
+             std::vector<const char *> excludes;
              add_using_directive (&local_using_directives,
-                                  dest, src, NULL, NULL, NULL, 1,
+                                  dest, src, NULL, NULL, excludes, 1,
                                   &objfile->objfile_obstack);
            }
          /* The "+ 2" is for the "::".  */
index 30b0fe8412b9f77f13845aa05b81bad5410194b8..a123ea7024920683135dabc3a38efa2ad4ca22fd 100644 (file)
@@ -9221,8 +9221,7 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
   const char *import_alias;
   const char *imported_declaration = NULL;
   const char *import_prefix;
-  VEC (const_char_ptr) *excludes = NULL;
-  struct cleanup *cleanups;
+  std::vector<const char *> excludes;
 
   import_attr = dwarf2_attr (die, DW_AT_import, cu);
   if (import_attr == NULL)
@@ -9296,8 +9295,6 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
   else
     canonical_name = imported_name;
 
-  cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes);
-
   if (die->tag == DW_TAG_imported_module && cu->language == language_fortran)
     for (child_die = die->child; child_die && child_die->tag;
         child_die = sibling_die (child_die))
@@ -9337,7 +9334,7 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
            continue;
          }
 
-       VEC_safe_push (const_char_ptr, excludes, imported_name);
+       excludes.push_back (imported_name);
 
        process_die (child_die, cu);
       }
@@ -9350,8 +9347,6 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
                       excludes,
                       0,
                       &objfile->objfile_obstack);
-
-  do_cleanups (cleanups);
 }
 
 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
@@ -14617,9 +14612,10 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
        {
          const char *previous_prefix = determine_prefix (die, cu);
 
+         std::vector<const char *> excludes;
          add_using_directive (using_directives (cu->language),
                               previous_prefix, TYPE_NAME (type), NULL,
-                              NULL, NULL, 0, &objfile->objfile_obstack);
+                              NULL, excludes, 0, &objfile->objfile_obstack);
        }
     }
 
index 5ada8132e532ce61ae43ef14acbb74bdb0e44179..a851ce9b5f915f694840e228ced765c7f4e10658 100644 (file)
@@ -39,7 +39,7 @@ add_using_directive (struct using_direct **using_directives,
                     const char *src,
                     const char *alias,
                     const char *declaration,
-                    VEC (const_char_ptr) *excludes,
+                    const std::vector<const char *> &excludes,
                     int copy_names,
                     struct obstack *obstack)
 {
@@ -52,7 +52,6 @@ add_using_directive (struct using_direct **using_directives,
   for (current = *using_directives; current != NULL; current = current->next)
     {
       int ix;
-      const char *param;
 
       if (strcmp (current->import_src, src) != 0)
        continue;
@@ -70,12 +69,11 @@ add_using_directive (struct using_direct **using_directives,
        continue;
 
       /* Compare the contents of EXCLUDES.  */
-      for (ix = 0; VEC_iterate (const_char_ptr, excludes, ix, param); ix++)
+      for (ix = 0; ix < excludes.size (); ++ix)
        if (current->excludes[ix] == NULL
-           || strcmp (param, current->excludes[ix]) != 0)
+           || strcmp (excludes[ix], current->excludes[ix]) != 0)
          break;
-      if (ix < VEC_length (const_char_ptr, excludes)
-         || current->excludes[ix] != NULL)
+      if (ix < excludes.size () || current->excludes[ix] != NULL)
        continue;
 
       /* Parameters exactly match CURRENT.  */
@@ -83,8 +81,7 @@ add_using_directive (struct using_direct **using_directives,
     }
 
   alloc_len = (sizeof(*newobj)
-              + (VEC_length (const_char_ptr, excludes)
-                 * sizeof(*newobj->excludes)));
+              + (excludes.size () * sizeof(*newobj->excludes)));
   newobj = (struct using_direct *) obstack_alloc (obstack, alloc_len);
   memset (newobj, 0, sizeof (*newobj));
 
@@ -114,9 +111,9 @@ add_using_directive (struct using_direct **using_directives,
   else
     newobj->declaration = declaration;
 
-  memcpy (newobj->excludes, VEC_address (const_char_ptr, excludes),
-         VEC_length (const_char_ptr, excludes) * sizeof (*newobj->excludes));
-  newobj->excludes[VEC_length (const_char_ptr, excludes)] = NULL;
+  memcpy (newobj->excludes, excludes.data (),
+         excludes.size () * sizeof (*newobj->excludes));
+  newobj->excludes[excludes.size ()] = NULL;
 
   newobj->next = *using_directives;
   *using_directives = newobj;
index 75ae0300227a6b0a7b262ce127be78eba1c9dd13..6804582110260249dc5780a150da3575ceb23fdb 100644 (file)
@@ -111,7 +111,7 @@ extern void add_using_directive (struct using_direct **using_directives,
                                 const char *src,
                                 const char *alias,
                                 const char *declaration,
-                                VEC (const_char_ptr) *excludes,
+                                const std::vector<const char *> &excludes,
                                 int copy_names,
                                  struct obstack *obstack);