btrace: Use function segment index in call iterator.
[deliverable/binutils-gdb.git] / gdb / cp-support.c
index d409b0b92e72854bd004003fbd46a8c3704ccf54..5704466c923bd3800a913c3cd040805e1b487929 100644 (file)
@@ -1,5 +1,5 @@
 /* Helper routines for C++ support in GDB.
-   Copyright (C) 2002-2016 Free Software Foundation, Inc.
+   Copyright (C) 2002-2017 Free Software Foundation, Inc.
 
    Contributed by MontaVista Software.
 
@@ -95,24 +95,6 @@ copy_string_to_obstack (struct obstack *obstack, const char *string,
   return (char *) obstack_copy (obstack, string, *len);
 }
 
-/* A cleanup wrapper for cp_demangled_name_parse_free.  */
-
-static void
-do_demangled_name_parse_free_cleanup (void *data)
-{
-  struct demangle_parse_info *info = (struct demangle_parse_info *) data;
-
-  cp_demangled_name_parse_free (info);
-}
-
-/* Create a cleanup for C++ name parsing.  */
-
-struct cleanup *
-make_cleanup_cp_demangled_name_parse_free (struct demangle_parse_info *info)
-{
-  return make_cleanup (do_demangled_name_parse_free_cleanup, info);
-}
-
 /* Return 1 if STRING is clearly already in canonical form.  This
    function is conservative; things which it does not recognize are
    assumed to be non-canonical, and the parser will sort them out
@@ -209,8 +191,7 @@ inspect_type (struct demangle_parse_info *info,
          long len;
          int is_anon;
          struct type *type;
-         struct demangle_parse_info *i;
-         struct ui_file *buf;
+         std::unique_ptr<demangle_parse_info> i;
 
          /* Get the real type of the typedef.  */
          type = check_typedef (otype);
@@ -246,23 +227,21 @@ inspect_type (struct demangle_parse_info *info,
                type = last;
            }
 
-         buf = mem_fileopen ();
+         string_file buf;
          TRY
-         {
-           type_print (type, "", buf, -1);
-         }
-
+           {
+             type_print (type, "", &buf, -1);
+           }
          /* If type_print threw an exception, there is little point
             in continuing, so just bow out gracefully.  */
          CATCH (except, RETURN_MASK_ERROR)
            {
-             ui_file_delete (buf);
              return 0;
            }
          END_CATCH
 
-         name = ui_file_obsavestring (buf, &info->obstack, &len);
-         ui_file_delete (buf);
+         len = buf.size ();
+         name = (char *) obstack_copy0 (&info->obstack, buf.c_str (), len);
 
          /* Turn the result into a new tree.  Note that this
             tree will contain pointers into NAME, so NAME cannot
@@ -272,7 +251,7 @@ inspect_type (struct demangle_parse_info *info,
          if (i != NULL)
            {
              /* Merge the two trees.  */
-             cp_merge_demangle_parse_infos (info, ret_comp, i);
+             cp_merge_demangle_parse_infos (info, ret_comp, i.get ());
 
              /* Replace any newly introduced typedefs -- but not
                 if the type is anonymous (that would lead to infinite
@@ -319,7 +298,7 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info,
 {
   long len;
   char *name;
-  struct ui_file *buf = mem_fileopen ();
+  string_file buf;
   struct demangle_component *comp = ret_comp;
 
   /* Walk each node of the qualified name, reconstructing the name of
@@ -333,9 +312,9 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info,
        {
          struct demangle_component newobj;
 
-         ui_file_write (buf, d_left (comp)->u.s_name.s,
-                        d_left (comp)->u.s_name.len);
-         name = ui_file_obsavestring (buf, &info->obstack, &len);
+         buf.write (d_left (comp)->u.s_name.s, d_left (comp)->u.s_name.len);
+         len = buf.size ();
+         name = (char *) obstack_copy0 (&info->obstack, buf.c_str (), len);
          newobj.type = DEMANGLE_COMPONENT_NAME;
          newobj.u.s_name.s = name;
          newobj.u.s_name.len = len;
@@ -348,12 +327,11 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info,
                 string and replace the top DEMANGLE_COMPONENT_QUAL_NAME
                 node.  */
 
-             ui_file_rewind (buf);
+             buf.clear ();
              n = cp_comp_to_string (&newobj, 100);
              if (n == NULL)
                {
                  /* If something went astray, abort typedef substitutions.  */
-                 ui_file_delete (buf);
                  return;
                }
 
@@ -378,14 +356,13 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info,
          if (name == NULL)
            {
              /* If something went astray, abort typedef substitutions.  */
-             ui_file_delete (buf);
              return;
            }
-         fputs_unfiltered (name, buf);
+         buf.puts (name);
          xfree (name);
        }
 
-      ui_file_write (buf, "::", 2);
+      buf.write ("::", 2);
       comp = d_right (comp);
     }
 
@@ -395,8 +372,9 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info,
 
   if (comp->type == DEMANGLE_COMPONENT_NAME)
     {
-      ui_file_write (buf, comp->u.s_name.s, comp->u.s_name.len);
-      name = ui_file_obsavestring (buf, &info->obstack, &len);
+      buf.write (comp->u.s_name.s, comp->u.s_name.len);
+      len = buf.size ();
+      name = (char *) obstack_copy0 (&info->obstack, buf.c_str (), len);
 
       /* Replace the top (DEMANGLE_COMPONENT_QUAL_NAME) node
         with a DEMANGLE_COMPONENT_NAME node containing the whole
@@ -408,8 +386,6 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info,
     }
   else
     replace_typedefs (info, comp, finder, data);
-
-  ui_file_delete (buf);
 }
 
 
@@ -518,6 +494,7 @@ replace_typedefs (struct demangle_parse_info *info,
        case DEMANGLE_COMPONENT_RESTRICT_THIS:
        case DEMANGLE_COMPONENT_POINTER:
        case DEMANGLE_COMPONENT_REFERENCE:
+       case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
          replace_typedefs (info, d_left (ret_comp), finder, data);
          break;
 
@@ -540,22 +517,19 @@ cp_canonicalize_string_full (const char *string,
 {
   std::string ret;
   unsigned int estimated_len;
-  struct demangle_parse_info *info;
+  std::unique_ptr<demangle_parse_info> info;
 
   estimated_len = strlen (string) * 2;
   info = cp_demangled_name_to_comp (string, NULL);
   if (info != NULL)
     {
       /* Replace all the typedefs in the tree.  */
-      replace_typedefs (info, info->tree, finder, data);
+      replace_typedefs (info.get (), info->tree, finder, data);
 
       /* Convert the tree back into a string.  */
       ret = cp_comp_to_string (info->tree, estimated_len);
       gdb_assert (!ret.empty ());
 
-      /* Free the parse information.  */
-      cp_demangled_name_parse_free (info);
-
       /* Finally, compare the original string with the computed
         name, returning NULL if they are the same.  */
       if (ret == string)
@@ -581,7 +555,7 @@ cp_canonicalize_string_no_typedefs (const char *string)
 std::string
 cp_canonicalize_string (const char *string)
 {
-  struct demangle_parse_info *info;
+  std::unique_ptr<demangle_parse_info> info;
   unsigned int estimated_len;
 
   if (cp_already_canonical (string))
@@ -593,7 +567,6 @@ cp_canonicalize_string (const char *string)
 
   estimated_len = strlen (string) * 2;
   std::string ret = cp_comp_to_string (info->tree, estimated_len);
-  cp_demangled_name_parse_free (info);
 
   if (ret.empty ())
     {
@@ -614,12 +587,11 @@ cp_canonicalize_string (const char *string)
    freed when finished with the tree, or NULL if none was needed.
    OPTIONS will be passed to the demangler.  */
 
-static struct demangle_parse_info *
+static std::unique_ptr<demangle_parse_info>
 mangled_name_to_comp (const char *mangled_name, int options,
                      void **memory, char **demangled_p)
 {
   char *demangled_name;
-  struct demangle_parse_info *info;
 
   /* If it looks like a v3 mangled name, then try to go directly
      to trees.  */
@@ -631,7 +603,7 @@ mangled_name_to_comp (const char *mangled_name, int options,
                                          options, memory);
       if (ret)
        {
-         info = cp_new_demangle_parse_info ();
+         std::unique_ptr<demangle_parse_info> info (new demangle_parse_info);
          info->tree = ret;
          *demangled_p = NULL;
          return info;
@@ -646,7 +618,8 @@ mangled_name_to_comp (const char *mangled_name, int options,
   
   /* If we could demangle the name, parse it to build the component
      tree.  */
-  info = cp_demangled_name_to_comp (demangled_name, NULL);
+  std::unique_ptr<demangle_parse_info> info
+    = cp_demangled_name_to_comp (demangled_name, NULL);
 
   if (info == NULL)
     {
@@ -666,7 +639,7 @@ cp_class_name_from_physname (const char *physname)
   void *storage = NULL;
   char *demangled_name = NULL, *ret;
   struct demangle_component *ret_comp, *prev_comp, *cur_comp;
-  struct demangle_parse_info *info;
+  std::unique_ptr<demangle_parse_info> info;
   int done;
 
   info = mangled_name_to_comp (physname, DMGL_ANSI,
@@ -745,7 +718,6 @@ cp_class_name_from_physname (const char *physname)
 
   xfree (storage);
   xfree (demangled_name);
-  cp_demangled_name_parse_free (info);
   return ret;
 }
 
@@ -815,7 +787,7 @@ method_name_from_physname (const char *physname)
   void *storage = NULL;
   char *demangled_name = NULL, *ret;
   struct demangle_component *ret_comp;
-  struct demangle_parse_info *info;
+  std::unique_ptr<demangle_parse_info> info;
 
   info = mangled_name_to_comp (physname, DMGL_ANSI,
                               &storage, &demangled_name);
@@ -832,7 +804,6 @@ method_name_from_physname (const char *physname)
 
   xfree (storage);
   xfree (demangled_name);
-  cp_demangled_name_parse_free (info);
   return ret;
 }
 
@@ -847,7 +818,7 @@ cp_func_name (const char *full_name)
 {
   char *ret;
   struct demangle_component *ret_comp;
-  struct demangle_parse_info *info;
+  std::unique_ptr<demangle_parse_info> info;
 
   info = cp_demangled_name_to_comp (full_name, NULL);
   if (!info)
@@ -859,7 +830,6 @@ cp_func_name (const char *full_name)
   if (ret_comp != NULL)
     ret = cp_comp_to_string (ret_comp, 10);
 
-  cp_demangled_name_parse_free (info);
   return ret;
 }
 
@@ -872,7 +842,7 @@ cp_remove_params (const char *demangled_name)
 {
   int done = 0;
   struct demangle_component *ret_comp;
-  struct demangle_parse_info *info;
+  std::unique_ptr<demangle_parse_info> info;
   char *ret = NULL;
 
   if (demangled_name == NULL)
@@ -905,7 +875,6 @@ cp_remove_params (const char *demangled_name)
   if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME)
     ret = cp_comp_to_string (d_left (ret_comp), 10);
 
-  cp_demangled_name_parse_free (info);
   return ret;
 }
 
@@ -1273,7 +1242,7 @@ make_symbol_overload_list_adl_namespace (struct type *type,
   int i, prefix_len;
 
   while (TYPE_CODE (type) == TYPE_CODE_PTR
-        || TYPE_CODE (type) == TYPE_CODE_REF
+        || TYPE_IS_REFERENCE (type)
          || TYPE_CODE (type) == TYPE_CODE_ARRAY
          || TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
     {
This page took 0.028788 seconds and 4 git commands to generate.