public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Move find_toplevel_char to cp-support.[ch]
@ 2022-02-25  0:48 Keith Seitz
  0 siblings, 0 replies; only message in thread
From: Keith Seitz @ 2022-02-25  0:48 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2f2c677e670063360cbb3fb1b32bd6cf36bcf03a

commit 2f2c677e670063360cbb3fb1b32bd6cf36bcf03a
Author: Keith Seitz <keiths@redhat.com>
Date:   Thu Feb 24 16:42:22 2022 -0800

    Move find_toplevel_char to cp-support.[ch]
    
    find_toplevel_char is being used more and more outside of linespec.c, so
    this patch moves it into cp-support.[ch].

Diff:
---
 gdb/cp-support.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/cp-support.h |  7 ++++++
 gdb/linespec.c   | 77 --------------------------------------------------------
 gdb/linespec.h   |  7 ------
 4 files changed, 81 insertions(+), 84 deletions(-)

diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 0be1a04852f..501d96d43cd 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -2199,6 +2199,80 @@ info_vtbl_command (const char *arg, int from_tty)
   cplus_print_vtable (value);
 }
 
+/* See description in cp-support.h.  */
+
+const char *
+find_toplevel_char (const char *s, char c)
+{
+  int quoted = 0;		/* zero if we're not in quotes;
+				   '"' if we're in a double-quoted string;
+				   '\'' if we're in a single-quoted string.  */
+  int depth = 0;		/* Number of unclosed parens we've seen.  */
+  const char *scan;
+
+  for (scan = s; *scan; scan++)
+    {
+      if (quoted)
+	{
+	  if (*scan == quoted)
+	    quoted = 0;
+	  else if (*scan == '\\' && *(scan + 1))
+	    scan++;
+	}
+      else if (*scan == c && ! quoted && depth == 0)
+	return scan;
+      else if (*scan == '"' || *scan == '\'')
+	quoted = *scan;
+      else if (*scan == '(' || *scan == '<')
+	depth++;
+      else if ((*scan == ')' || *scan == '>') && depth > 0)
+	depth--;
+      else if (*scan == 'o' && !quoted && depth == 0)
+	{
+	  /* Handle C++ operator names.  */
+	  if (strncmp (scan, CP_OPERATOR_STR, CP_OPERATOR_LEN) == 0)
+	    {
+	      scan += CP_OPERATOR_LEN;
+	      if (*scan == c)
+		return scan;
+	      while (ISSPACE (*scan))
+		{
+		  ++scan;
+		  if (*scan == c)
+		    return scan;
+		}
+	      if (*scan == '\0')
+		break;
+
+	      switch (*scan)
+		{
+		  /* Skip over one less than the appropriate number of
+		     characters: the for loop will skip over the last
+		     one.  */
+		case '<':
+		  if (scan[1] == '<')
+		    {
+		      scan++;
+		      if (*scan == c)
+			return scan;
+		    }
+		  break;
+		case '>':
+		  if (scan[1] == '>')
+		    {
+		      scan++;
+		      if (*scan == c)
+			return scan;
+		    }
+		  break;
+		}
+	    }
+	}
+    }
+
+  return 0;
+}
+
 void _initialize_cp_support ();
 void
 _initialize_cp_support ()
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index cd473a2c553..4fbd53c8923 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -190,4 +190,11 @@ extern struct cmd_list_element *maint_cplus_cmd_list;
 
 gdb::unique_xmalloc_ptr<char> gdb_demangle (const char *name, int options);
 
+/* Find an instance of the character C in the string S that is outside
+   of all parenthesis pairs, single-quoted strings, and double-quoted
+   strings.  Also, ignore the char within a template name, like a ','
+   within foo<int, int>.  */
+
+extern const char *find_toplevel_char (const char *s, char c);
+
 #endif /* CP_SUPPORT_H */
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 707a3a2586a..4d41f74ab2f 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1298,83 +1298,6 @@ find_methods (struct type *t, enum language t_lang, const char *name,
     superclasses->push_back (TYPE_BASECLASS (t, ibase));
 }
 
-/* Find an instance of the character C in the string S that is outside
-   of all parenthesis pairs, single-quoted strings, and double-quoted
-   strings.  Also, ignore the char within a template name, like a ','
-   within foo<int, int>, while considering C++ operator</operator<<.  */
-
-const char *
-find_toplevel_char (const char *s, char c)
-{
-  int quoted = 0;		/* zero if we're not in quotes;
-				   '"' if we're in a double-quoted string;
-				   '\'' if we're in a single-quoted string.  */
-  int depth = 0;		/* Number of unclosed parens we've seen.  */
-  const char *scan;
-
-  for (scan = s; *scan; scan++)
-    {
-      if (quoted)
-	{
-	  if (*scan == quoted)
-	    quoted = 0;
-	  else if (*scan == '\\' && *(scan + 1))
-	    scan++;
-	}
-      else if (*scan == c && ! quoted && depth == 0)
-	return scan;
-      else if (*scan == '"' || *scan == '\'')
-	quoted = *scan;
-      else if (*scan == '(' || *scan == '<')
-	depth++;
-      else if ((*scan == ')' || *scan == '>') && depth > 0)
-	depth--;
-      else if (*scan == 'o' && !quoted && depth == 0)
-	{
-	  /* Handle C++ operator names.  */
-	  if (strncmp (scan, CP_OPERATOR_STR, CP_OPERATOR_LEN) == 0)
-	    {
-	      scan += CP_OPERATOR_LEN;
-	      if (*scan == c)
-		return scan;
-	      while (isspace (*scan))
-		{
-		  ++scan;
-		  if (*scan == c)
-		    return scan;
-		}
-	      if (*scan == '\0')
-		break;
-
-	      switch (*scan)
-		{
-		  /* Skip over one less than the appropriate number of
-		     characters: the for loop will skip over the last
-		     one.  */
-		case '<':
-		  if (scan[1] == '<')
-		    {
-		      scan++;
-		      if (*scan == c)
-			return scan;
-		    }
-		  break;
-		case '>':
-		  if (scan[1] == '>')
-		    {
-		      scan++;
-		      if (*scan == c)
-			return scan;
-		    }
-		  break;
-		}
-	    }
-	}
-    }
-
-  return 0;
-}
-
 /* The string equivalent of find_toplevel_char.  Returns a pointer
    to the location of NEEDLE in HAYSTACK, ignoring any occurrences
    inside "()" and "<>".  Returns NULL if NEEDLE was not found.  */
diff --git a/gdb/linespec.h b/gdb/linespec.h
index bf9b04008a8..bb8975548a3 100644
--- a/gdb/linespec.h
+++ b/gdb/linespec.h
@@ -162,13 +162,6 @@ extern const char *get_gdb_linespec_parser_quote_characters (void);
 
 extern int is_ada_operator (const char *string);
 
-/* Find an instance of the character C in the string S that is outside
-   of all parenthesis pairs, single-quoted strings, and double-quoted
-   strings.  Also, ignore the char within a template name, like a ','
-   within foo<int, int>.  */
-
-extern const char *find_toplevel_char (const char *s, char c);
-
 /* Find the end of the (first) linespec pointed to by *STRINGP.
    STRINGP will be advanced to this point.  */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-02-25  0:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-25  0:48 [binutils-gdb] Move find_toplevel_char to cp-support.[ch] Keith Seitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).