From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Add pretty printer for std::regex internals
Date: Wed, 5 Jan 2022 13:48:34 +0000 [thread overview]
Message-ID: <20220105134834.1640093-1-jwakely@redhat.com> (raw)
Tested powerpc64le-linux, pushed to trunk.
This helps visualize the NFA states in a std::regex. It probably isn't
very useful for users, but helps when working on the implementation.
libstdc++-v3/ChangeLog:
* python/libstdcxx/v6/printers.py (StdRegexStatePrinter): New
printer for std::regex NFA states.
---
libstdc++-v3/python/libstdcxx/v6/printers.py | 32 ++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 84a54698c17..44f1148d5ab 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1554,6 +1554,34 @@ class StdErrorCodePrinter:
pass
return '%s = {"%s": %s}' % (self.typename, category, strval)
+class StdRegexStatePrinter:
+ "Print a state node in the NFA for a std::regex"
+
+ def __init__ (self, typename, val):
+ self.val = val
+ self.typename = typename
+
+ def to_string (self):
+ opcode = str(self.val['_M_opcode'])
+ if opcode:
+ opcode = opcode[25:]
+ next_id = self.val['_M_next']
+
+ variants = {'repeat':'alt', 'alternative':'alt',
+ 'subexpr_begin':'subexpr', 'subexpr_end':'subexpr',
+ 'line_begin_assertion':None, 'line_end_assertion':None,
+ 'word_boundary':'neg', 'subexpr_lookahead':'neg',
+ 'backref':'backref_index',
+ 'match':None, 'accept':None,
+ 'dummy':None, 'unknown':None
+ }
+ v = variants[opcode]
+
+ s = "opcode={}, next={}".format(opcode, next_id)
+ if v is not None and self.val['_M_' + v] is not None:
+ s = "{}, {}={}".format(s, v, self.val['_M_' + v])
+ return "{%s}" % (s)
+
# A "regular expression" printer which conforms to the
# "SubPrettyPrinter" protocol from gdb.printing.
class RxPrinter(object):
@@ -2015,6 +2043,10 @@ def build_libstdcxx_dictionary ():
libstdcxx_printer.add_version('std::tr1::', 'unordered_multiset',
Tr1UnorderedSetPrinter)
+ # std::regex components
+ libstdcxx_printer.add_version('std::__detail::', '_State',
+ StdRegexStatePrinter)
+
# These are the C++11 printer registrations for -D_GLIBCXX_DEBUG cases.
# The tr1 namespace containers do not have any debug equivalents,
# so do not register printers for them.
--
2.31.1
reply other threads:[~2022-01-05 13:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220105134834.1640093-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.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).