From: Keith Seitz <keiths@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/3] Move find_toplevel_char to utils.[ch]
Date: Fri, 02 Feb 2018 18:36:00 -0000 [thread overview]
Message-ID: <20180202183642.4288-1-keiths@redhat.com> (raw)
find_toplevel_char is being used more and more outside of linespec.c, so
this patch moves it into utils.[ch].
gdb/ChangeLog:
* linespec.c (find_toplevel_char): Moved to ...
* utils.c (find_toplevel_char): ... here.
* linespec.h (find_toplevel_char): Moved to ...
* utils.h (find_toplevel_char): ... here.
---
gdb/linespec.c | 77 ----------------------------------------------------------
gdb/linespec.h | 7 ------
gdb/utils.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
gdb/utils.h | 7 ++++++
4 files changed, 81 insertions(+), 84 deletions(-)
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 1236b3f475..247b285b99 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1277,83 +1277,6 @@ find_methods (struct type *t, enum language t_lang, const char *name,
VEC_safe_push (typep, *superclasses, 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 eced085e3e..2649af9e4f 100644
--- a/gdb/linespec.h
+++ b/gdb/linespec.h
@@ -163,13 +163,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. */
diff --git a/gdb/utils.c b/gdb/utils.c
index c531748fe4..0a072fee6b 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -3431,6 +3431,80 @@ strip_leading_path_elements (const char *path, int n)
return p;
}
+/* See description in utils.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_utils (void)
{
diff --git a/gdb/utils.h b/gdb/utils.h
index b234762929..c1195f65b5 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -559,4 +559,11 @@ extern void dump_core (void);
extern char *make_hex_string (const gdb_byte *data, size_t length);
+/* 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 /* UTILS_H */
--
2.13.6
next reply other threads:[~2018-02-02 18:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-02 18:36 Keith Seitz [this message]
2018-02-02 18:36 ` [PATCH 2/3] Remove hard-coded line number from templates.exp Keith Seitz
2018-02-05 17:03 ` Yao Qi
2018-02-02 18:36 ` [PATCH 3/3] Support template lookups in strncmp_iw_with_mode Keith Seitz
2018-02-06 18:15 ` Pedro Alves
2018-02-06 19:24 ` Keith Seitz
2018-02-21 23:46 ` Keith Seitz
2018-02-05 17:02 ` [PATCH 1/3] Move find_toplevel_char to utils.[ch] Yao Qi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180202183642.4288-1-keiths@redhat.com \
--to=keiths@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).