From patchwork Tue Feb 21 12:02:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60071 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1848883wrn; Tue, 21 Feb 2023 05:03:12 -0800 (PST) X-Google-Smtp-Source: AK7set9mgdmHX78hrZFnOGhJBSt3odXaF9ZH41pKkQfYAx3B+S5vOBu6/IePOfqMe6WROUZJbvCK X-Received: by 2002:a17:906:f4f:b0:8b1:2d35:2264 with SMTP id h15-20020a1709060f4f00b008b12d352264mr13911820ejj.73.1676984592722; Tue, 21 Feb 2023 05:03:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984592; cv=none; d=google.com; s=arc-20160816; b=Tp3nVfpUD4TZJZZ8TRPFvmli5jYr1xJFpf1SgtLVtvqYwGi4NaIpJ6tHjpl1BrKoW7 MwzQS0OuCjF+F4sQ7v859coDn2JZg1LL/+Rv3EOQAkmSn6xks6sorNwFDK3P6o/EDfMf va2i/qWojLsDLaqkOPVsxNAOEjLX32gShiA9fL5awRPB8g0bLpm5s7tXguCoEOvCZFRV jFyZpaZPWXZjBWdngFLaBKODVtCS2DM/HhfSRL28PGuKQd6bl53wCugygQ9bXw3yssHE mf3PqG7i2XyXyH8w+iErpRf6nqP3/FejP5jGSqYuJ0AWrn/00ehn8LczvaQdSMHUDoRV LI4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dmarc-filter :delivered-to; bh=80461fre8+hQ0zMopblsV380dH0N+AStk+XMfdir8cY=; b=bKXaJmUKTvmqMH45FS2haMsdV4pl1mp+9iSxjMcPPrX6IMXf4uhMtqsBELL+PkN1sa GZ0RhLTKRxnbAY61dizWB7JQgWVbFjJWoLgTDqnakj37TceFgKi7ejYyYpIS+lTc48ab Od7Xm+lHcz/PNo0QpwbSLjaI/nsus6IDj+LEnrPZt+5sYC0zE0ytosUM/ZKfJNqVYPCd I/Hv/W6Py7OwnvqsqfqrU494qZrXsnRuWKf2Rzzs9di6NuxdpMxc1fXtZVBCmKJIjtXs fvMPEgDlALIMnhLNLjavHg1P4SAhvF1pQzGV3zaz90wg/NVF5OvNbOngF3ZbCtzIER9k O+KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Ab23yKxH; 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 cm3-20020a170907938300b008cf2b9f412csi6432870ejc.67.2023.02.21.05.03.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 05:03:12 -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=Ab23yKxH; 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 34A8F3902A51 for ; Tue, 21 Feb 2023 12:22:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id CBEAF382CD63 for ; Tue, 21 Feb 2023 12:04:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CBEAF382CD63 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-x430.google.com with SMTP id z8so3885694wrm.8 for ; Tue, 21 Feb 2023 04:04:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=80461fre8+hQ0zMopblsV380dH0N+AStk+XMfdir8cY=; b=Ab23yKxHbZ+wd7dUuVAYJgm8UQA5Fm909Cyj5qth6UFHyDJfvGViDLD7X3FiPCsL2D gjwtyd9b2miICMxGIv5RomNgY3uuNfy1Wz5vriXngXsIQbu8QhrhQsOaiBzmlB+Hy5fY stPawowJnbOTck8NqwDzSoh0TzztMmiOpcVk0cbY3Exql0P1Y5D8Yp0OUQ/xd4RWon6v hlg0ZT61yJ6Nw0FUs3Jme+lePueyx04RqudNTPBpc+O28TNpOd0yR59dx0cIUkajtwN3 L9MtVN3J5eaKW6ogXVgdfMch3+DitRFOyrQPesHLaU3L90rgmUzA5vHujNIaVyvga8VG QY7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=80461fre8+hQ0zMopblsV380dH0N+AStk+XMfdir8cY=; b=MWq6suAV/B7E3cLm0Ymy9zQnXb9y4DFCzAs6bD1WhUnEefi6SNe7H8NxIakJHOdDn1 sMZikiSi5L74Qu7K/K8i5oP61+7/2NEl9MtpwZFiI4HZmIncZc4hzaIWN+bHurvBRPrX fOZANeXfEi37gFZwvkvRBwmbe8AzmGnvoN3eNm2Iw+yc/4qd+WWraDe3AKGu/eNgFEFk d5F+8nkzrsDH/S9tJ7FczGYz73su09X5VaEQE64yoRE/nJHWZK7JRpAuxMu7pMT3CegJ y1yvFdfFVsL9Q1Y+pzChVkFEGz5ORnM61zO6OqmWD5JtLX9baq0LsaITPgfmNgpR3iOA XcSg== X-Gm-Message-State: AO0yUKVy+HtuuIJ72f73Db8xHSMTaHW+s9IZdbeEcLJ0eBUsZ+Y99Hz+ VKbap/UUuQ/DT2u+jwM1lRSp3qRC/qyGqKeiTQ== X-Received: by 2002:adf:fdce:0:b0:2c5:5ff8:6b01 with SMTP id i14-20020adffdce000000b002c55ff86b01mr4996763wrs.1.1676981073168; Tue, 21 Feb 2023 04:04:33 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:32 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 087/103] gccrs: ast: Dump generic parameters Date: Tue, 21 Feb 2023 13:02:17 +0100 Message-Id: <20230221120230.596966-88-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221120230.596966-1-arthur.cohen@embecosm.com> References: <20230221120230.596966-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.3 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: , Reply-To: arthur.cohen@embecosm.com 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?1758445796327637854?= X-GMAIL-MSGID: =?utf-8?q?1758445796327637854?= From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing visitor. * ast/rust-ast-dump.h: Likewise. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 129 +++++++++++++++++++++++++++++++--- gcc/rust/ast/rust-ast-dump.h | 3 + 2 files changed, 123 insertions(+), 9 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 216f0a43dc3..03a57d416c4 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -372,21 +372,134 @@ Dump::visit (PathInExpression &path) } void -Dump::visit (TypePathSegment &) -{} +Dump::visit (TypePathSegment &segment) +{ + // Syntax: + // PathIdentSegment + + stream << segment.get_ident_segment ().as_string (); +} void -Dump::visit (TypePathSegmentGeneric &) -{} +Dump::visit (TypePathSegmentGeneric &segment) +{ + // Syntax: + // PathIdentSegment `::`? (GenericArgs)? + // GenericArgs : + // `<` `>` + // | `<` ( GenericArg `,` )* GenericArg `,`? `>` + + stream << segment.get_ident_segment ().as_string (); + + if (segment.get_separating_scope_resolution ()) + stream << "::"; + + stream << "<"; + + { + // Here we join 3 lists (each possibly empty) with a separator. + + auto &lifetime_args = segment.get_generic_args ().get_lifetime_args (); + auto &generic_args = segment.get_generic_args ().get_generic_args (); + auto &binding_args = segment.get_generic_args ().get_binding_args (); + + visit_items_joined_by_separator (lifetime_args, ", "); + if (!lifetime_args.empty () + && (!generic_args.empty () || !binding_args.empty ())) + { + // Insert separator if some items have been already emitted and some + // more are to be emitted from any of the following collections. + stream << ", "; + } + visit_items_joined_by_separator (generic_args, ", "); + if (!generic_args.empty () && !binding_args.empty ()) + { + // Insert separator if some item vas emitted from the previous + // collection and more are to be emitted from the last. + stream << ", "; + } + visit_items_joined_by_separator (binding_args, ", "); + } + + stream << ">"; +} void -Dump::visit (TypePathSegmentFunction &) -{} +Dump::visit (GenericArgsBinding &binding) +{ + // Syntax: + // IDENTIFIER `=` Type + + stream << binding.get_identifier () << " << "; + visit (binding.get_type ()); +} + +void +Dump::visit (GenericArg &arg) +{ + // `GenericArg` implements `accept_vis` but it is not useful for this case as + // it ignores unresolved cases (`Kind::Either`). + + switch (arg.get_kind ()) + { + case GenericArg::Kind::Const: + visit (arg.get_expression ()); + break; + case GenericArg::Kind::Type: + visit (arg.get_type ()); + break; + case GenericArg::Kind::Either: + stream << arg.get_path (); + break; + case GenericArg::Kind::Error: + gcc_unreachable (); + } +} // namespace AST + +void +Dump::visit (TypePathSegmentFunction &segment) +{ + // Syntax: + // PathIdentSegment `::`? (TypePathFn)? + + stream << segment.get_ident_segment ().as_string (); + + if (segment.get_separating_scope_resolution ()) + stream << "::"; + + if (!segment.is_ident_only ()) + visit (segment.get_type_path_function ()); +} + +void +Dump::visit (TypePathFunction &type_path_fn) +{ + // Syntax: + // `(` TypePathFnInputs? `)` (`->` Type)? + // TypePathFnInputs : + // Type (`,` Type)* `,`? + + stream << '('; + if (type_path_fn.has_inputs ()) + visit_items_joined_by_separator (type_path_fn.get_params (), ", "); + stream << ')'; + + if (type_path_fn.has_return_type ()) + { + stream << "->"; + visit (type_path_fn.get_return_type ()); + } +} void Dump::visit (TypePath &path) { - stream << path.as_string (); + // Syntax: + // `::`? TypePathSegment (`::` TypePathSegment)* + + if (path.has_opening_scope_resolution_op ()) + stream << "::"; + visit_items_joined_by_separator (path.get_segments (), "::"); } void @@ -897,8 +1010,6 @@ Dump::visit (TypeParam ¶m) // TypeParamBounds : // TypeParamBound ( + TypeParamBound )* +? - // FIXME this outputs things like "Ambiguous: String" - this comes from - // Token::str stream << param.get_type_representation (); if (param.has_type_param_bounds ()) { diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 6c2f13c8c01..4bc322cda98 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -139,6 +139,9 @@ private: void visit (std::vector &for_lifetimes); void visit (FunctionQualifiers &qualifiers); void visit (MaybeNamedParam ¶m); + void visit (TypePathFunction &type_path_fn); + void visit (GenericArgsBinding &binding); + void visit (GenericArg &arg); // rust-ast.h void visit (Token &tok);