From patchwork Tue Jan 31 13:24:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 50851 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2747760wrn; Tue, 31 Jan 2023 05:24:03 -0800 (PST) X-Google-Smtp-Source: AK7set/1uvu5l5ZeygCQIal17m2uIiGJicsUua7FQv7F9bBGiHOAngOlDkdtgHzTo69xQIrJqHnm X-Received: by 2002:a05:6402:2421:b0:49e:ed9c:215f with SMTP id t33-20020a056402242100b0049eed9c215fmr22617459eda.38.1675171443041; Tue, 31 Jan 2023 05:24:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675171443; cv=none; d=google.com; s=arc-20160816; b=Yhe/NczXduiQyhHstwN3yC5dReslExJdjLkmqbB84qYQfsSUHFqMoq9nOzsjV1JeOY bwHxxGUdOJczJsn8iyjjCiFfoYLfYY/deB7K/g8xYME/8ivpF7F3jEEq4VOUp6lp+T9u 0CtfperkSbcc5VUMaMa+IPp0834DgqfahWp5ati+I1Ytf3qvOF0SjXf9B6CzYZ3slM+v a30np+K+n7WBHxlZgCO44lJ2wZw/+YhxKgmufCGgv3FzqXzTTDrArWmit4h8O4wFOlWn uwJloOn51eTC1SS2jB8RGV84F2nfYPqLJEhXX55GLQGZox9EPp3M7T1+1t59eh5mj54H p/cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=qyVyIehw7oczWyNIUsS8JhzD29U6rMVszZ/Uu5gW3yg=; b=DHEVbUztdBS0X3H4PdragC19uQJRpJvlglEOMFOe8WrOKGxI4D+1V29X9HDcQEBFtB brVx9n94yggvfSjK3kQP7FPy+DdcCLZF3A7dvEUV5aU+wyTiihI02Lw2RDCHWHXxVr2Y GcpB1CHauA8TYPLYws6ecgkKSQWMGZzA0dMG1aaBfYL5CD0fscJ8H06smT0zf6kDv4j7 v/Cs78sVebhHz+CY8aWkzPJ1ZVzq0Bg0ysLkqNqbck4oMHULYGt9CieB7QKvyBVCzjGg pw0Tp/4Zie/uwbx+ELMVyNRn+3uiBVchkntt8/HAroAACJ9DQXjp7C/JMsJgaP5+HlP2 cKZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=cub7Ziir; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e24-20020a170906749800b0087bd76ce97dsi17849080ejl.112.2023.01.31.05.24.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 05:24:03 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=cub7Ziir; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B5F9F389EC54 for ; Tue, 31 Jan 2023 13:21:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 5CCF63889E20 for ; Tue, 31 Jan 2023 13:21:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5CCF63889E20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x434.google.com with SMTP id r2so14171698wrv.7 for ; Tue, 31 Jan 2023 05:21:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qyVyIehw7oczWyNIUsS8JhzD29U6rMVszZ/Uu5gW3yg=; b=cub7ZiirzzusqeZYhqe8Kf80V77IkMIOEPVRiHzXOFp+H3bGQRf7OxXizV6EarsnQo 1aNbzkF6LloScc4DGiS6vRcqjOXVKMc1uPE63UNSUCASmsMHCpkPrdWACOpeDhYFIi1+ +gcyE5l2y241NnWZJDon+F6c3FblAiNkmvyLHZd7af6QtGnTaJVyCbIVruq+zTcC+t+S N3sBzT+lU/rAhfDb5YWkCjTBJcLGVITsqFFNK5Xp1nQVExlDn+FgDdKc8j3ADtKUX2r8 bUQxviZbPqZ0EVdd7xST/YBaJldOXITIckJ7vqOJlFrdEN2srW+m++zZhBWnMkk86fl+ Iqsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qyVyIehw7oczWyNIUsS8JhzD29U6rMVszZ/Uu5gW3yg=; b=xe5fiJjbntG058W/GkJ1D3rZIKSWtw+R5QMMnpwba1Kx7qBoAiiGIhXoeBnX3rR1kR aW+Q4tm0myY9g9AfEf+NBFY1nHIqWDEbrdgbEi7eqDNW41aznhovnRXRVS9ORmGAwAkE mSIIVq07VZUahhb9HGDPyT6hsz5K0ldlKZUq4hG0ALjS0/DczELSJNND1RugHPOtskpY lRYEmDLQtXi1PoxJDdwX/liaTRpBKWADYVnQTsc/W5472D6JyP15lSkm6znaCBeKk/i6 5CP4pUSOO/eTGz4SYWR65JHQGLbc6ZT/EEeUrzbyor4rq+2UVdIvRHmmgNW5YNKlCJoq e+Tg== X-Gm-Message-State: AFqh2koDN7cfhb04w/umr7cebWwmpYRIZBBCkapHZJpWYVSU9qFqm13B umNjKRsaM3Ym1aJZkOD7ZbGRwTi1PdKS/ci5CQ== X-Received: by 2002:adf:e197:0:b0:2be:546f:50c2 with SMTP id az23-20020adfe197000000b002be546f50c2mr41279298wrb.12.1675171272702; Tue, 31 Jan 2023 05:21:12 -0800 (PST) Received: from platypus.lan ([2001:861:5e4c:3bb0:6424:328a:1734:3249]) by smtp.gmail.com with ESMTPSA id v13-20020a5d43cd000000b0027cb20605e3sm14737683wrr.105.2023.01.31.05.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 05:21:12 -0800 (PST) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED] gccrs: dump: Add AST debugging using the AST::Dump class Date: Tue, 31 Jan 2023 14:24:56 +0100 Message-Id: <20230131132456.661762-1-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-15.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756544570739824723?= X-GMAIL-MSGID: =?utf-8?q?1756544570739824723?= gcc/rust/ChangeLog: * ast/rust-ast-dump.h: Add shorthand `AST::Dump::debug` function to dump an AST node on `stderr`. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/ast/rust-ast-dump.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 4fa4db9265f..955dbc0bebc 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -52,6 +52,22 @@ public: void go (AST::Crate &crate); void go (AST::Item &item); + /** + * Use the AST Dump as a debugging tool + */ + template static void debug (T &instance) + { + auto dump = Dump (std::cerr); + + std::cerr << '\n'; + instance.accept_vis (dump); + std::cerr << '\n'; + } + template static void debug (std::unique_ptr &instance) + { + debug (*instance); + } + private: std::ostream &stream; Indent indentation;