Factor out final completion match string building
[deliverable/binutils-gdb.git] / gdb / symtab.c
index a249a8d98eaeb3ebf091d3982a9c875137adb8b5..bb98619a7cb891c438148bdcd2253da8ec0df719 100644 (file)
@@ -729,7 +729,6 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
 {
   char *demangled = NULL;
   int i;
-  int recognized;
 
   if (gsymbol->language == language_unknown)
     gsymbol->language = language_auto;
@@ -4283,7 +4282,6 @@ search_symbols (const char *regexp, enum search_domain kind,
          and <TYPENAME> or <OPERATOR>.  */
       const char *opend;
       const char *opname = operator_chars (regexp, &opend);
-      int errcode;
 
       if (*opname)
        {
@@ -4698,7 +4696,7 @@ compare_symbol_name (const char *symbol_name, language symbol_language,
   symbol_name_matcher_ftype *name_match
     = language_get_symbol_name_matcher (lang, lookup_name);
 
-  return name_match (symbol_name, lookup_name, &match_res.match);
+  return name_match (symbol_name, lookup_name, &match_res);
 }
 
 /*  See symtab.h.  */
@@ -4727,31 +4725,17 @@ completion_list_add_name (completion_tracker &tracker,
      of matches.  Note that the name is moved to freshly malloc'd space.  */
 
   {
-    char *newobj;
-
-    if (word == text)
-      {
-       newobj = (char *) xmalloc (strlen (symname) + 5);
-       strcpy (newobj, symname);
-      }
-    else if (word > text)
-      {
-       /* Return some portion of symname.  */
-       newobj = (char *) xmalloc (strlen (symname) + 5);
-       strcpy (newobj, symname + (word - text));
-      }
-    else
-      {
-       /* Return some of SYM_TEXT plus symname.  */
-       newobj = (char *) xmalloc (strlen (symname) + (text - word) + 5);
-       strncpy (newobj, word, text - word);
-       newobj[text - word] = '\0';
-       strcat (newobj, symname);
-      }
-
-    gdb::unique_xmalloc_ptr<char> completion (newobj);
-
-    tracker.add_completion (std::move (completion));
+    gdb::unique_xmalloc_ptr<char> completion
+      = make_completion_match_str (symname, text, word);
+
+    /* Here we pass the match-for-lcd object to add_completion.  Some
+       languages match the user text against substrings of symbol
+       names in some cases.  E.g., in C++, "b push_ba" completes to
+       "std::vector::push_back", "std::string::push_back", etc., and
+       in this case we want the completion lowest common denominator
+       to be "push_back" instead of "std::".  */
+    tracker.add_completion (std::move (completion),
+                           &match_res.match_for_lcd);
   }
 }
 
@@ -5317,30 +5301,7 @@ static void
 add_filename_to_list (const char *fname, const char *text, const char *word,
                      completion_list *list)
 {
-  char *newobj;
-  size_t fnlen = strlen (fname);
-
-  if (word == text)
-    {
-      /* Return exactly fname.  */
-      newobj = (char *) xmalloc (fnlen + 5);
-      strcpy (newobj, fname);
-    }
-  else if (word > text)
-    {
-      /* Return some portion of fname.  */
-      newobj = (char *) xmalloc (fnlen + 5);
-      strcpy (newobj, fname + (word - text));
-    }
-  else
-    {
-      /* Return some of TEXT plus fname.  */
-      newobj = (char *) xmalloc (fnlen + (text - word) + 5);
-      strncpy (newobj, word, text - word);
-      newobj[text - word] = '\0';
-      strcat (newobj, fname);
-    }
-  list->emplace_back (newobj);
+  list->emplace_back (make_completion_match_str (fname, text, word));
 }
 
 static int
This page took 0.028602 seconds and 4 git commands to generate.