From patchwork Wed Jan 5 13:48:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1575671 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=PtfheYQ4; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JTWNz4tvdz9sCD for ; Thu, 6 Jan 2022 01:01:22 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D67CD385801D for ; Wed, 5 Jan 2022 14:01:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D67CD385801D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641391279; bh=uUNjslNClPcZbm/RmeOM1/Xm8UZZo0P0rT9JCrvLgvY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=PtfheYQ4rOZiqvlJp4BBfW6GIj8WKtPxuqlFUdHFOKyiYmf7nHtBTpQKFPWerqfTS DJCIHhgfu/h3DJrRdRYGVXZe6/6fumyywfdIirr655F8Ii0ZXQIbRj1KtKZV/APRpo PPt7C6U803b/ojy+aSTm8t3ClRy7aZA/O739mfEY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 1479C3858008 for ; Wed, 5 Jan 2022 13:48:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1479C3858008 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-587-7VaBGtgbOzq6rmLvDTKmiQ-1; Wed, 05 Jan 2022 08:48:36 -0500 X-MC-Unique: 7VaBGtgbOzq6rmLvDTKmiQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A333510168D2; Wed, 5 Jan 2022 13:48:35 +0000 (UTC) Received: from localhost (unknown [10.33.36.252]) by smtp.corp.redhat.com (Postfix) with ESMTP id 555D677467; Wed, 5 Jan 2022 13:48:35 +0000 (UTC) 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 Message-Id: <20220105134834.1640093-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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.